Swing垂直分割的窗格示例

广告位

SplitPane类用于在两个面板之间进行可移动分割。 示例 package com.yiibai.swing…

SplitPane类用于在两个面板之间进行可移动分割。

示例

package com.yiibai.swingdemo;  import java.awt.BorderLayout; import java.awt.FlowLayout;  import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.JTextField;  public class SwingTester {    public static void main(String[] args) {       createWindow();    }     private static void createWindow() {           JFrame frame = new JFrame("Swing垂直分割的窗格示例");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       createUI(frame);       frame.setSize(560, 200);             frame.setLocationRelativeTo(null);         frame.setVisible(true);    }     private static void createUI(final JFrame frame){         JPanel buttonPanel = new JPanel(new FlowLayout());       buttonPanel.add(new JButton("确定"));       buttonPanel.add(new JButton("取消"));           JPanel textBoxPanel = new JPanel(new FlowLayout());       textBoxPanel.add(new JLabel("名称:"));       textBoxPanel.add(new JTextField(20));       JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, buttonPanel, textBoxPanel);       splitPane.setOneTouchExpandable(true);       splitPane.setDividerLocation(50);       frame.getContentPane().add(splitPane, BorderLayout.CENTER);          } } 

执行上面示例代码,得到以下结果:

Swing垂直分割的窗格示例

  

拾荒的老头

关于作者: 拾荒的老头

为您推荐