Reputation: 3
I've to created a custom jdialog but i want it a bit small. It should not have empty space. The following code gives me this:
If I decrease the size using setSize, it results into a bad GUI like this:
class Find extends JDialog
{
JPanel f1,f2,f3,rp;
JLabel fl,filler1,filler2,filler3;
JTextField ft,fillert;
JCheckBox mcase;
JButton fb1,fb2;
JRadioButton upr,dr;
ButtonGroup rg;
public Find()
{
setTitle("Find");
f3 = new JPanel();
f3.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
f3.setLayout(new GridLayout(3,1));
f1 = new JPanel();
f1.setLayout(new BoxLayout(f1,BoxLayout.X_AXIS));
f2 = new JPanel();
f2.setLayout(new BoxLayout(f2,BoxLayout.X_AXIS));
fl = new JLabel("Find what: ");
ft = new JTextField();
fb1 = new JButton(" Find ");
mcase = new JCheckBox("Match case",false);
fb2 = new JButton("Cancel");
rg = new ButtonGroup();
upr = new JRadioButton("Up");
dr = new JRadioButton("Down");
rg.add(upr);
rg.add(dr);
rp = new JPanel();
rp.add(upr);
rp.add(dr);
filler1 = new JLabel(" ");
filler2 = new JLabel(" ");
f1.add(fl);
f1.add(ft);
f1.add(filler1);
f1.add(fb1);
f2.add(mcase);
f2.add(rp);
//f2.add(filler2);
//f2.add(fb2);
f3.add(f1);
//f3.add(new JLabel());
f3.add(f2);
add(f3);
setSize(400,120);
setAlwaysOnTop(true);
setResizable(false);
setVisible(true);
}
}
Upvotes: 0
Views: 57
Reputation: 3
f3.setLayout(new GridLayout(2,1));
ft.setMaximumSize(new Dimension(250,25));
The above changes did the trick!
Upvotes: 0
Reputation: 17534
Your f3 JPanel
has a GridLayout
with 3 rows, and the third one is empty .
You only need 2, so try :
f3.setLayout(new GridLayout(2,1));
OR :
Change the LayoutManager of f3 to a vertical BoxLayout
f3.setLayout(new BoxLayout(f3, BoxLayout.Y_AXIS));
And reduce the height of the JDialog
:
setSize(400,100);
Upvotes: 1