I'm trying to get the Layout of a JDialog
of mine to fit a particular look that a program in which I'm porting to Java has, I've used several LayoutManagers before with great success yet for some reason I cannot seem to get this working at all. My goal is to have the Right (East) side of the JDialog
contain a "Find Next" and "Cancel" button in a top-down order and then any extra space below so that the two buttons are always at the top of the JDialog
, yet for some reason BoxLayout
is continously ignoring any attempts at changing (this is where I'm lost) the width of a JButton
. Code follows.
JButton findNext = new JButton("Find Next");
JButton cancel = new JButton("Cancel");
cancel.setPreferredSize(new Dimension((int)findNext.getPreferredSize().getWidth(),
(int)cancel.getPreferredSize().getHeight()));
JPanel example = new JPanel();
example.setLayout(new BoxLayout(example, BoxLayout.Y_AXIS));
example.add(findNext);
example.add(cancel);
example.add(Box.createGlue());
No matter what I try, cancel
always retains it's normal size. I've tried setMinimumSize()
and setMaximumSize()
with the same parameters as setPreferredSize
with no luck. I've even tried cancel.setPreferredSize(new Dimension(500, 500));
and the buttons height was the only thing adjusted, it STILL retained the default width it was given.
To clear up any questoins, here is a link to what it looks like (now that I've finished it) and you'll see that the "Find Next" and "Cancel" buttons are not the same size.