Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

adding two jpanels to contentpane ... layoutmanger messes up these panels.

843805Apr 29 2006 — edited May 1 2006
Gruff bring u swing problem!

Ive tried countless of layoutmanger combinations and the closest
I get to the result I want is when I use the code below.

Sadly ... GridBagLayout() creates exactly equally sized cells and I
want the first row (panel with tabbed panes) to be 90% of the total window. Most layoutmanger combinations just messes the JTabbedPane up into a messy ball of tabs, some stretches the button to fill the entire cell.

I tried GridBagLayout but got a headache ... and a ball of tabs. How would
you guys set this up? The result I want is looking somewhat like this in asciiart.

JFrame gui:
------------------------------------
| outer JTabbedPane with |
| inner JTabbedPanes on |
| each tab |
| |
|-----------------------------------
| JPanel with buttons |
-----------------------------------

Right now I have collected the JTabbedPanes on a JPanel and I get
the expected result using a BorderLayout(). As for the JPanel with buttons,
for them to be left aligned and not stretched I use a SpringLayout(). Finally
I'd like to place the two JPanels on the JFrame ContentPane ... and here
is where my problem occurs.

Please help :)
	public void gui() {
		
	    // Create GUI
	    gui = new JFrame("Minirc");

	    // Create Servers Panel
	    serversPanel = new JPanel();
            serversPanel.setLayout(new BorderLayout());
            serverTabsPane = new JTabbedPane();
            serverTabsPane.setTabPlacement(JTabbedPane.LEFT);
	    sw = new ServerWindow("server1");
            serverTabsPane.add("Server1", sw);
            serversPanel.add(serverTabsPane);
 
            // Create Buttons Panel
            buttonsPanel = new JPanel();
            buttonsPanel.setLayout(new SpringLayout());
            button = new JButton("Java");
            button.setSize(new Dimension(3,3));
            buttonsPanel.add(button);

            // Assemble GUI
            Container background = gui.getContentPane();
            GridLayout layout = new GridLayout();
            layout.setRows(2);
            background.setLayout(layout);
            background.add(serversPanel);
            background.add(buttonsPanel);
        
            // Setup and show GUI
            gui.setSize((int) screen.getWidth(), (int) screen.getHeight());
	    gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            gui.setVisible(true);	    
	}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 29 2006
Added on Apr 29 2006
1 comment
136 views