Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / July 2007

Tip: Looking for answers? Try searching our database.

UI Layout

Thread view: 
Philippe Massicotte - 23 Jul 2007 15:16 GMT
Hi all, I'm new to UI with java and I'm trying to learn how to setup
position and stuff.

I created a JFrame with a JPanel that contains a TabbedPane.

For the moment the JPanel is set to south but its very small.  I would like
to change its size (height) so its like 50% of my total JFrame height.

Here's my code (sorry for the layout) :

public class hh extends JFrame {
private static final long serialVersionUID = 1;
private JPanel jContentPane = null;
private JPanel jPanel = null;
private JTabbedPane jTabbedPane = null;
private JPanel jPanel1 = null;
private JTabbedPane jTabbedPane1 = null;
private JPanel jPanel2 = null;
private JTabbedPane jTabbedPane2 = null;
public hh() throws HeadlessException {
// TODO Auto-generated constructor stub
super();
initialize();
}

private JPanel getJPanel() {
   if (jPanel == null) {
   GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
   gridBagConstraints1.fill = GridBagConstraints.BOTH;
   gridBagConstraints1.weighty = 10.0;
   gridBagConstraints1.weightx = 10.0;
gridBagConstraints1.gridheight=100;
jPanel = new JPanel();
jPanel.setLayout(new BorderLayout());
jPanel.setBorder(BorderFactory.createLineBorder(Color.blue, 6));
jPanel.setSize(10, 10);
jPanel.add(getJTabbedPane(), BorderLayout.SOUTH);
//jPanel.add(getJTabbedPane(),(Object)gridBagConstraints1);
}
return jPanel;
}

private JTabbedPane getJTabbedPane() {
   if (jTabbedPane == null) {
   jTabbedPane = new JTabbedPane();
   jTabbedPane.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
   jTabbedPane.addTab(null, null, getJPanel1(), null);
   jTabbedPane.addTab(null, null, getJPanel2(), null);
}
return jTabbedPane;
}

private JPanel getJPanel1() {
if (jPanel1 == null) {
/*GridBagConstraints gridBagConstraints = new GridBagConstraints();
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.weighty = 2.0;
gridBagConstraints.weightx = 100.0;*/
jPanel1 = new JPanel();
jPanel1.setLayout(new GridBagLayout());
jPanel1.add(getJTabbedPane1(), null);
}
return jPanel1;
}

private JTabbedPane getJTabbedPane1() {
if (jTabbedPane1 == null) {
jTabbedPane1 = new JTabbedPane();
}
return jTabbedPane1;
}

private JPanel getJPanel2() {
if (jPanel2 == null) {
jPanel2 = new JPanel();
jPanel2.setLayout(new GridBagLayout());
jPanel2.add(getJTabbedPane2(),null);
}
return jPanel2;
}

private JTabbedPane getJTabbedPane2() {
if (jTabbedPane2 == null) {
jTabbedPane2 = new JTabbedPane();
}
return jTabbedPane2;
}

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {
public void run() {
hh thisClass = new hh();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}

private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
}

private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJPanel(),BorderLayout.SOUTH);
//jContentPane.add(getJPanel(), BorderLayout.SOUTH);
//jContentPane.add(getJButton(), BorderLayout.NORTH);
}
return jContentPane;
}
}
Roedy Green - 24 Jul 2007 08:42 GMT
>For the moment the JPanel is set to south but its very small.  I would like
>to change its size (height) so its like 50% of my total JFrame height.

I switch to GridBagLayout as soon as I want fine control of how it
renders.  See http://mindprod.com/jgloss/layout.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.