将对象停靠在角落 - MigLayout
Dock objects in the corner - MigLayout
如何在角落停靠三个或更多组件,例如。东南使用 MigLayout ?
我尝试了什么:
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import net.miginfocom.swing.MigLayout;
public class App {
public static void launchView(){
JFrame frame = new JFrame("Foo");
frame.setLayout(new MigLayout());
JButton b1 = new JButton("Sample1");
JButton b2 = new JButton("Sample2");
JButton b3 = new JButton("Sample3");
frame.add(b1, "dock south, east");
frame.add(b2);
frame.add(b3);
frame.setSize(new Dimension(600, 200));
frame.setVisible(true);
}
public static void main(String [] args){
SwingUtilities.invokeLater(new Runnable() {
public void run() {
launchView();
}
});
}
}
在图片中,您可以看到按钮以错误的顺序显示在左角,但我希望它们始终位于西南角,一个挨着另一个 (Button1 | Button2 | Button3)。
尝试使用 SceneBuilder,这是一个适用于 Eclipse 的插件,NetBeans.You 可以使用该工具轻松构建 GUI。
你自己的一个潜在解决方案是使用这个:
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new MigLayout("", "[grow,right]", "[grow,bottom]"));
JButton btnNewButton = new JButton("New button");
frame.getContentPane().add(btnNewButton, "flowx,cell 0 0");
JButton btnNewButton_1 = new JButton("New button");
frame.getContentPane().add(btnNewButton_1, "cell 0 0");
JButton btnNewButton_2 = new JButton("New button");
frame.getContentPane().add(btnNewButton_2, "cell 0 0");
如何在角落停靠三个或更多组件,例如。东南使用 MigLayout ? 我尝试了什么:
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import net.miginfocom.swing.MigLayout;
public class App {
public static void launchView(){
JFrame frame = new JFrame("Foo");
frame.setLayout(new MigLayout());
JButton b1 = new JButton("Sample1");
JButton b2 = new JButton("Sample2");
JButton b3 = new JButton("Sample3");
frame.add(b1, "dock south, east");
frame.add(b2);
frame.add(b3);
frame.setSize(new Dimension(600, 200));
frame.setVisible(true);
}
public static void main(String [] args){
SwingUtilities.invokeLater(new Runnable() {
public void run() {
launchView();
}
});
}
}
在图片中,您可以看到按钮以错误的顺序显示在左角,但我希望它们始终位于西南角,一个挨着另一个 (Button1 | Button2 | Button3)。
尝试使用 SceneBuilder,这是一个适用于 Eclipse 的插件,NetBeans.You 可以使用该工具轻松构建 GUI。
你自己的一个潜在解决方案是使用这个:
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new MigLayout("", "[grow,right]", "[grow,bottom]"));
JButton btnNewButton = new JButton("New button");
frame.getContentPane().add(btnNewButton, "flowx,cell 0 0");
JButton btnNewButton_1 = new JButton("New button");
frame.getContentPane().add(btnNewButton_1, "cell 0 0");
JButton btnNewButton_2 = new JButton("New button");
frame.getContentPane().add(btnNewButton_2, "cell 0 0");