JSplitPane实现面板的上下两部分的分割

import java.awt.Color;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextField;

public class FriendList1 {

	private JFrame frame;
	private JSplitPane jsp1;
	private JPanel jp_top, jp_bottom;
	
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					FriendList1 window = new FriendList1();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public FriendList1() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 281, 621);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		// 上下分割
		jsp1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
		jp_bottom = new JPanel();
		jp_bottom.setBackground(Color.red);
		jp_top = new JPanel();
		jp_top.setBackground(Color.BLUE);
		jsp1.setTopComponent(jp_top);
		jsp1.setBottomComponent(jp_bottom);
		jsp1.setDividerLocation(40);
		
		frame.add(jsp1);
		frame.setSize(240, 600);
		frame.setVisible(true);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_41262903/article/details/80862350