Java – how to use components on a row with multiple components in miglayout

Miglayout was started a month and a half ago. Everything is very simple and the effect is very good I have another problem that I haven't solved yet

Suppose I want to arrange the two rightmost buttons and a centered title. When I do this, the title is not actually centered:

(this is JPanel)

this.add(labelTitle,"split,span,center");
this.add(closeButton,"east");
this.add(mainMenuButton,"east");

What happens is that the "label title" is centered in the remaining space after the button is placed, but I actually want it to be centered relative to the entire JPanel, not just the remaining space

What parameters can I use to achieve the desired effect? I know I can use absolute positioning, but I don't want to do so because it violates the purpose of using miglayout first in my case

Solution

Can it be like what you're looking for?

Cheers, Mikel grave

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);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>