Java Swing Border 效果 预览

阅读更多

BorderFactory 中的Border样式比较多,写一个测试以示区别:

public class TestSwingBorder extends JFrame {

	private static final long serialVersionUID = 3711916627794200840L;

	public TestSwingBorder() throws HeadlessException {
		initComponpent();
	}

	private JPanel createBorderDemoPanel(Border border, String string) {
		JPanel panel = new JPanel();
		JTextArea textArea = new JTextArea();
		textArea.setEditable(false);
		textArea.setText(string);
		textArea.setLineWrap(true);
		panel.add(textArea);
		panel.setBorder(border);
		return panel;
	}

	private void initComponpent() {
		JPanel contentPanel = new JPanel();
		contentPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
		contentPanel.setBounds(20, 20, 300, 300);
		contentPanel.setLayout(new GridLayout(3, 3, 10, 10));

		JPanel panel = createBorderDemoPanel(
				BorderFactory.createRaisedBevelBorder(),
				"BorderFactory.createRaisedBevelBorder()");

		contentPanel.add(panel);

		panel = createBorderDemoPanel(
				BorderFactory.createRaisedSoftBevelBorder(),
				"BorderFactory.createRaisedSoftBevelBorder()");
		contentPanel.add(panel);

		panel = createBorderDemoPanel(BorderFactory.createEtchedBorder(),
				"BorderFactory.createEtchedBorder()");
		contentPanel.add(panel);

		panel = createBorderDemoPanel(
				BorderFactory.createLineBorder(Color.RED),
				"BorderFactory.createLineBorder(Color.RED)");
		contentPanel.add(panel);

		panel = createBorderDemoPanel(BorderFactory.createLoweredBevelBorder(),
				"BorderFactory.createLoweredBevelBorder()");
		contentPanel.add(panel);

		panel = createBorderDemoPanel(
				BorderFactory.createLoweredSoftBevelBorder(),
				"BorderFactory.createLoweredSoftBevelBorder()");
		contentPanel.add(panel);

		panel = createBorderDemoPanel(BorderFactory.createCompoundBorder(),
				"BorderFactory.createCompoundBorder()");
		contentPanel.add(panel);

		panel = createBorderDemoPanel(
				BorderFactory.createStrokeBorder(new BasicStroke(10)),
				"BorderFactory.createStrokeBorder(new BasicStroke(10))");
		contentPanel.add(panel);

		panel = createBorderDemoPanel(
				BorderFactory.createMatteBorder(10, 10, 10, 10, Color.blue),
				"BorderFactory.createMatteBorder(10, 10, 10, 10,Color.blue)");
		contentPanel.add(panel);

		panel = createBorderDemoPanel(
				BorderFactory.createTitledBorder(
						BorderFactory.createRaisedSoftBevelBorder(), "这是标题",
						TitledBorder.LEFT, TitledBorder.TOP),
				"BorderFactory.createTitledBorder(BorderFactory.createRaisedSoftBevelBorder(), \"这是标题\",TitledBorder.LEFT, TitledBorder.TOP)");
		contentPanel.add(panel);

		setContentPane(contentPanel);
	}

	public static void main(String[] args) {
		TestSwingBorder testSwingBorder = new TestSwingBorder();
		testSwingBorder.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		testSwingBorder.setSize(600, 600);
		testSwingBorder.setLocationRelativeTo(null);
		testSwingBorder.setVisible(true);
	}
}

 效果如下:


Java Swing Border 效果 预览_第1张图片
 

 

  • Java Swing Border 效果 预览_第2张图片
  • 大小: 39.6 KB
  • 查看图片附件

你可能感兴趣的:(Java,Swing,Border,BorderFactory,demo)