Reputation: 4944
I just started using MigLayout for SWING in Java and I'm really liking it so far. The only thing, though, is that the dock parameters don't seem to work the way I thought they worked and I can't figure out what I'm doing wrong.
The problem is: I'm trying to add a JButton inside a JPanel and docking it to the right side using panel.add(button, "east");. While it actually makes it the rightmost component, it still only takes the same space as it would in a flowLayout. What I'd like it to do is stick to the right side of the panel.
Here's some compilable code that recreates the problem:
public class MigLayoutTest extends JFrame
{
public MigLayoutTest()
{
setSize(500,500);
JPanel panel = new JPanel(new MigLayout());
panel.setBackground(Color.YELLOW);
setContentPane(panel);
panel.setSize(500,500);
panel.add(new JButton("Dock east"), "east");
panel.add(new JButton("No dock"));
}
public static void main(String[] args)
{
JFrame frame = new MigLayoutTest();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Here's what the output looks like:
And here's where I'd want the "dock east" button:
If I'm using the parameters wrong, I'd like it if someone could tell me how I'm supposed to make my button dock to the right side of the panel.
Thanks!
Upvotes: 3
Views: 1920
Reputation: 17359
You have to specify growth paarameters:
new MigLayout("", "[grow]", "[]")
Be careful though how you use it - it may not work the way you think it is. Here is a good read up on MigLayout features http://www.miglayout.com/QuickStart.pdf
Upvotes: 4