ram*_*ram 4 java swing jcomponent layout-manager
如何使用Swing将这些JComponents与"内容"窗格中心的"表单"对齐...
panel1.add(l1);
panel1.add(c1);
panel1.add(l2);
panel1.add(c2);
panel1.add(b4);
panel1.add(b5);
frame1.getContentPane().add(panel1);
Run Code Online (Sandbox Code Playgroud)
请帮我
您首先阅读容器中的Laying Out Components教程怎么样?我滥用了这个说法但是,总是不止一种方法给猫皮肤
下面是一个使用多余的例子BoxLayout,并setAlignmentX(...)在JComponent实例-
public final class StackComponentsDemo {
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
createAndShowGUI();
}
});
}
private static void createAndShowGUI(){
final JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(new DisabledJButton());
panel.add(new DisabledJButton());
panel.add(new DisabledJButton());
panel.add(new DisabledJButton());
panel.add(new DisabledJButton());
frame.add(panel);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static final class DisabledJButton extends JButton{
public DisabledJButton(){
super("Disabled");
setEnabled(false);
setAlignmentX(Component.CENTER_ALIGNMENT);
}
}
}
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
1130 次 |
| 最近记录: |