Results 1 to 6 of 6

Thread: Panel sizing

  1. #1
    sjs
    sjs is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default Panel sizing

    I have the following code example. It contains a Frame, within the Frame is a TabbedPanel, and in the left tabbed panel is a SplitPane. The problem is the split panes are very small. I thought using the BorderLayout.CENTER when I added the split pane to the tabbed pane, would make the split pane use the full size. What needs to change in the code to get the split pane the full size?

    Thanks for any help.


    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    
    import javax.swing.*;
    import javax.swing.border.*;
    
    public class szTest extends JFrame {
    
            // Variables
            private JTabbedPane tabbedPane;
            private JPanel leftTabPane, rightTabPane;
            private JPanel leftSplitPane, rightSplitPane;
            private JSplitPane splitPane;
    
            // Constructor
            public szTest()
            {
                    tabbedPane = new JTabbedPane();
        
                    // left tab pane
                    leftTabPane = new JPanel(false);
                    tabbedPane.addTab("Left Tab", leftTabPane);
                    leftTabPane.setBorder(new LineBorder(Color.blue, 3));
    
        
                    // right tab pane
                    rightTabPane = new JPanel(false);
                    tabbedPane.addTab("Right Tab", rightTabPane);
                    rightTabPane.setBorder(new LineBorder(Color.cyan, 3));
        
    
                    //Create a split pane
                    leftSplitPane = new JPanel(false);
                    rightSplitPane = new JPanel(false);
                    leftSplitPane.setBorder(new LineBorder(Color.green, 2));
                    rightSplitPane.setBorder(new LineBorder(Color.red, 2));
                    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,
                                               leftSplitPane, rightSplitPane);
    
                    splitPane.setDividerLocation(0.5);
                    splitPane.setResizeWeight(0.5);
    
                    // add split pane to left tab panel
                    leftTabPane.add(splitPane, BorderLayout.CENTER);
    
                    // add the tabbed panel to the frame
                    add(tabbedPane, BorderLayout.CENTER);
    
                    //add WindowListener for closing frame and ending program
                    addWindowListener(new WindowAdapter() {
                                    public void windowClosed(WindowEvent e)
                                    {
                                            System.exit(0);
                                    }
                            }
                    );
                    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }       //End of Contructor
    
            public static void main(String args[]) {
                    szTest sv = new szTest();
                    Container contentPane = sv.getContentPane();
                    sv.setTitle("Panel Size Test");
                    sv.setSize(600, 400);
                    sv.setLocation(400, 250);
                    sv.setVisible(true);
                    sv.setResizable(true);
            }
    
    }               //End of Swing szTest Class.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by sjs View Post
    I have the following code example. It contains a Frame, within the Frame is a TabbedPanel, and in the left tabbed panel is a SplitPane. The problem is the split panes are very small. I thought using the BorderLayout.CENTER when I added the split pane to the tabbed pane, would make the split pane use the full size.
    Only if the container that the component being added in fact uses BorderLayout. I don't see where you have set the layout of any of your containers here.

  3. #3
    sjs
    sjs is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Only if the container that the component being added in fact uses BorderLayout. I don't see where you have set the layout of any of your containers here.
    I thought the content frame uses BorderLayout by default.

  4. #4
    sjs
    sjs is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by sjs View Post
    I thought the content frame uses BorderLayout by default.
    I added:

    leftTabPane.setLayout(new BorderLayout());

    And everything was as expected. When did the default BorderLayout get reset?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by sjs View Post
    I thought the content frame uses BorderLayout by default.
    It does, but you're not adding the split pane directly to the content pane; you're adding it to a JPanel which uses FlowLayout by default.

  6. #6
    sjs
    sjs is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    It does, but you're not adding the split pane directly to the content pane; you're adding it to a JPanel which uses FlowLayout by default.
    Thank you.

Similar Threads

  1. Add panel to parent panel
    By LovJava in forum AWT / Swing
    Replies: 10
    Last Post: 09-02-2010, 08:43 PM
  2. Replies: 3
    Last Post: 02-06-2010, 03:28 PM
  3. Adding a panel to a panel
    By rclausing in forum New To Java
    Replies: 7
    Last Post: 02-02-2010, 05:56 AM
  4. Trouble with Buffer Sizing
    By Jeff in forum New To Java
    Replies: 3
    Last Post: 02-07-2008, 01:43 PM
  5. Help needed with sizing components
    By adlb1300 in forum New To Java
    Replies: 2
    Last Post: 11-20-2007, 04:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •