开发者

MigLayout - Need help on how to use the dock parameters (or need an alternative)

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 fra开发者_高级运维me = new MigLayoutTest();
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

Here's what the output looks like:

MigLayout - Need help on how to use the dock parameters (or need an alternative)

And here's where I'd want the "dock east" button:

MigLayout - Need help on how to use the dock parameters (or need an alternative)

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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜