0

New to Java Swing layouts. After much reading, I think that the best layout for me is the box layout. My JDialogBox has a JTabbedPane on it. On the JTabbedPane, there are four JPanels. I am focusing on laying out one of these panels, called pnlDivision.

What I want to do to this panel is to add a series of scrollable panels. The panels will be vertically stacked upon each other and each will consist of a single row. Included in each panel will be horizontally aligned labels, any of which can be selected for editing by the user.

At the moment, I can't even get anything to appear on my tabbed panel. Focusing on the basics first, I have the following code just to get the idea of a box layout set up, with a single scrollable panel containing and a single label. But my tabbed panel is still blank. Can anyone see what is wrong with this basic code? I've read many resources on this, but I can't get unstuck.

Thanks very much !

    JScrollPane myScroller = new JScrollPane();
    myScroller.setPreferredSize(new Dimension(250, 80));
    myScroller.setAlignmentX(LEFT_ALIGNMENT);

    JPanel myPane = new JPanel();
    myPane.setLayout(new BoxLayout(myPane, BoxLayout.PAGE_AXIS));
    JLabel lbl = new JLabel("label 1");

    myPane.add(lbl);
    myPane.add(Box.createRigidArea(new Dimension(0,4)));
    myPane.add(myScroller);
    myPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

    pnlDivision.add(myPane);

EDIT:

This is the code where I set up the tabbed panel. I used the IDE (NetBeans), so this is generated by NetBeans. I've only pulled out the lines that relate to this issue. If I'm obviously missing any lines, please let me know:

jTabbedPane1 = new javax.swing.JTabbedPane();
pnlDivision = new javax.swing.JPanel();
jTabbedPane1.addTab("division", null, pnlDivision, "Manage Sets for Division Problems");
getContentPane().add(jTabbedPane1);
jTabbedPane1.setBounds(70, 110, 610, 340);
AndroidDev
  • 20,466
  • 42
  • 148
  • 239
  • 1
    I'm to no inched that the problem is with your box layou, but with how you are setting up the UI. Can you provide a runnable example of how you are setting up the a ingle tab? – MadProgrammer Feb 15 '13 at 23:31
  • 1
    Please post an [SSCCE](http://sscce.org). Btw, don't call `setSize()/setLocation()/setBounds()` nor `setPreferredSize()/setMaximumSize()/setMinimumSize()`. Instead leave all this code to an appropriate LayoutManager. Using any of the previous methods with LayoutManager's is just fighting against them and can only lead to unpredictable and clumsy behaviours as the one you describe. – Guillaume Polet Feb 15 '13 at 23:58

0 Answers0