-
JPanel / layout problems
Hey folks.. I am having a problem with using a few of the layouts within a JPanel. For some reason if I use flowlayout or gridlayout the components of the panel display. If i use springlayout, boxlayout, or absolute positioning the panel does not display. I have the panel embedded in a JFrame. Here is the code snippet for one of the panels in the application...
If i change the first line to modePanel = new JPanel(); it displays FYI
// Mode Panel Coding
modePanel = new JPanel(null);
lblModeSelect = new JLabel("Select a mode");
lblModeSelect.setFont(lblModeSelect.getFont().deri veFont(14.0f));
cmbModeSelect = new JComboBox(modeArray);
cmbModeSelect.setSelectedIndex(0);
// x, y, width, height
modePanel.add(lblModeSelect);
modePanel.add(cmbModeSelect);
lblModeSelect.setSize(lblModeSelect.getPreferredSi ze());
//lblModeSelect.setVisible(true);
modePanel.setSize(100,50);
System.out.println(lblModeSelect.getSize());
lblModeSelect.setBounds(1, 1, 55, 10);
cmbModeSelect.setBounds(1, 20, 55, 10);
content.add(modePanel);
content.validate();
//modePanel.setVisible(true);
content.layout.putConstraint(SpringLayout.WEST, modePanel,
1, SpringLayout.WEST, content);
content.layout.putConstraint(SpringLayout.NORTH, modePanel,
1, SpringLayout.NORTH, content);
cmbModeSelect.addActionListener(this);
-
Have you tried to set its layout to null? instead of Setting the LayoutManager to null(@ JPanel parameter)
eg. Code:
this.setLayout(null);
-
that would set the layout to the parent JFrame to null not the JPanel...
-
i assumed you've created a class that extends JPanel....
Nice implementation if you did...
objectPanel.setLayout(null);
-
no change with that, thx for the suggestion. I can gladly make a new class for each panel but I don't see any benefit to doin that in this app