Mar*_*ers 2 java swing jtoolbar
我写了以下内容,在右侧生成一个工具栏,只有它中的两个按钮一样高.我希望工具栏能够运行窗口的高度 - 从上到下.我需要做什么?
import javax.swing.*;
import java.awt.*;
public class AmtFrame extends JFrame {
private JToolBar toolBar = null;
private JButton[] buttons = new JButton[5];
private Container cp = null;
AmtFrame() {
super("AMT");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(1000, 600);
// tool bar
toolBar = new JToolBar("TaskBar", JToolBar.VERTICAL);
toolBar.add(buttons[0] = new JButton("Data Entry"));
toolBar.add(buttons[1] = new JButton("Operations"));
// layout
cp = getContentPane();
cp.setLayout(new BorderLayout());
cp.add(toolBar, BorderLayout.EAST);
}
public static void main(String[] args) {
new AmtFrame().setVisible(true);
}
}
Run Code Online (Sandbox Code Playgroud)
如果你不需要移动JToolBar这里是这段代码会产生的(我知道它可能不是你想要的确切的东西,但是LaF和我想的一样).
请注意,如果floatable为true并且您移动工具栏,则LaF将消失.
toolBar = new JToolBar("TaskBar", JToolBar.VERTICAL);
toolBar.setLayout(new GridLayout(12, 1));
toolBar.setFloatable(false);
toolBar.add(buttons[0] = new JButton("Data Entry"));
toolBar.add(buttons[1] = new JButton("Operations"));
toolBar.setOrientation(JToolBar.HORIZONTAL);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
513 次 |
| 最近记录: |