gpt4 book ai didi

java - 如何在java swing中垂直对齐按钮

转载 作者:行者123 更新时间:2023-12-02 07:17:49 24 4
gpt4 key购买 nike

我想垂直对齐 JButton 实例。您能建议一种方法吗?

Jbutton jb= new Jbutton();
Jbutton jb1= new Jbutton();
JButton jb3= new JBUtton();

最佳答案

引用下面的代码:

private void prepareUI() {
this.setUndecorated(true);
//Preparing control buttons
JButton jb = new MyButton("-");
jb.setActionCommand("Min");
jb.addActionListener(this);
jb1 = new MyButton("[]");//delete this line
jb1.setActionCommand("Max");
jb1.addActionListener(this);
JButton jb2 = new MyButton("X");
jb2.setActionCommand("Close");
jb2.addActionListener(this);
//Preparing panel
JPanel buttonPanel = new JPanel();
BoxLayout boxLayout1 = new BoxLayout(buttonPanel, BoxLayout.Y_AXIS);
buttonPanel.setLayout(boxLayout1);
buttonPanel.add(Box.createVerticalGlue());
buttonPanel.add(jb);
buttonPanel.add(jb1);
buttonPanel.add(jb2);
jb.setFocusable(false);
jb1.setFocusable(false);

jb2.setFocusable(false);

JPanel panel=new JPanel();
BoxLayout boxLayout = new BoxLayout(panel, BoxLayout.LINE_AXIS);
panel.setLayout(boxLayout);
panel.add(Box.createHorizontalGlue())

关于java - 如何在java swing中垂直对齐按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14703954/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com