Click to See Complete Forum and Search --> : setSize?


daileyps
September 14th, 2000, 04:31 PM
I've grouped objects into JPanels with x-axis boxlayout...this works fine as I now have the controls in the locations I want. Only problems now is how to get them the size I want. setSize is not working for me. I have JLabel, JTextBox, and JButton controls.

Example:

private Object[] dlgObjects = new Object[2];

private Dimension labelSize = new Dimension(50, 21);
private Dimension textSize = new Dimension(100, 21);
private Dimension buttonSize = new Dimension(21, 21);

dlgObjects[0] = new JPanel();

((JPanel)dlgObjects[0]).setLayout(new BoxLayout (((JPanel)dlgObjects[0]), BoxLayout.X_AXIS));

((JPanel)dlgObjects[0]).add(flpLabel);
((JPanel)dlgObjects[0]).add(flpText);
((JPanel)dlgObjects[0]).add(flpButton);

flpButton.setSize(buttonSize);
flpLabel.setSize(labelSize);
flpText.setSize(textSize);


dlgObjects[1] = new JPanel();

((JPanel)dlgObjects[1]).setLayout(new BoxLayout(((JPanel)dlgObjects[1]), BoxLayout.X_AXIS));

((JPanel)dlgObjects[1]).add(prpLabel);
((JPanel)dlgObjects[1]).add(prpText);
((JPanel)dlgObjects[1]).add(prpButton);

prpButton.setSize(buttonSize);
prpLabel.setSize(labelSize);
prpText.setSize(textSize);

kannanbalu
September 14th, 2000, 06:36 PM
Try setBounds();

Kannan

daileyps
September 15th, 2000, 01:19 PM
Thanks for the post, but that does not work either. I've also tried using setSize with setLocation, with and with out layout manager, and can still not size my components properly.

poochi
September 15th, 2000, 02:42 PM
try setPreferredSize(Dimension)

daileyps
September 15th, 2000, 03:07 PM
YES! This works, it was quite apparent I was mixing my AWT components wit Swing components again (tisk, tisk) when I tried this...changed my Label to JLabel and works like a charm...much thanks.