Ada*_*ith 11 java swing miglayout
大约一个半月前我开始使用MiGLayout,一切都很简单,效果很好.我还有一个问题,我无法修复.
假设我想要一行在最右侧有两个按钮和一个居中的标题,当我这样做时,标题实际上并没有居中:
("这个是JPanel")
this.add(labelTitle, "split, span, center");
this.add(closeButton, "east");
this.add(mainMenuButton, "east");
Run Code Online (Sandbox Code Playgroud)
发生的事情是"labelTitle"在放置按钮后的剩余可用空间中居中,但我实际上希望它相对于整个JPanel而不是仅剩余空间居中.
我可以使用哪些参数来获得所需的效果?我知道我可以使用绝对定位,但我不想这样做,因为它在我的案例中首先击败了使用MiGLayout的目的.
你能找到这样的东西吗?
干杯!
public static void main(String[] args)
{
JFrame frame = new JFrame();
JPanel panel = new JPanel(new MigLayout("debug"));
panel.add(new JLabel("Label Title"), "x2 min(b1.x - unrel, (container.w+pref)/2)");
panel.add(new JButton("Close Button"), "id b1, pushx, alignx right");
panel.add(new JButton("Main Menu Button"), "alignx right");
frame.add(panel);
frame.setSize(800, 200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setVisible(true);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3517 次 |
最近记录: |