设置边框

package swing;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;

public class BorderTest {
 public static void main(String[] args) {
  EventQueue.invokeLater(new Runnable() {
   @Override
   public void run() {
    BorderFrame frame = new BorderFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
   }
  });
 }
}

class BorderFrame extends JFrame {
 public BorderFrame() {
  this.setTitle("Border Test");
  this.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
  
  buttonPanel = new JPanel();
  demoPanel = new JPanel();
  group = new ButtonGroup();
  
  addRadioButton("Lowered bevel", BorderFactory.createLoweredBevelBorder());
  addRadioButton("Raised bevel", BorderFactory.createRaisedBevelBorder());
  addRadioButton("Etched", BorderFactory.createEtchedBorder());
  addRadioButton("Line", BorderFactory.createLineBorder(Color.BLUE));
  addRadioButton("Matte", BorderFactory.createMatteBorder(10, 10, 10, 10, Color.BLUE));
  addRadioButton("Empty", BorderFactory.createEmptyBorder());
  
  Border etched = BorderFactory.createEtchedBorder();
  Border titled = BorderFactory.createTitledBorder(etched, "Border types");
  buttonPanel.setBorder(titled);
  
  this.setLayout(new GridLayout(2, 1));
  this.add(buttonPanel);
  this.add(demoPanel);
 }
 
 private void addRadioButton(String buttonName, final Border b) {
  JRadioButton button = new JRadioButton(buttonName);
  button.addActionListener(new ActionListener() {
   @Override
   public void actionPerformed(ActionEvent event) {
    demoPanel.setBorder(b);
   }
  });
  group.add(button);
  buttonPanel.add(button);
 }

 public static final int DEFAULT_WIDTH = 600;
 public static final int DEFAULT_HEIGHT = 200;
 
 private JPanel buttonPanel;
 private JPanel demoPanel;
 private ButtonGroup group;
}

阅读更多
个人分类: swing
想对作者说点什么? 我来说一句

背景透明Panel

2011年12月04日 302KB 下载

cicleImageView(as)

2016年12月19日 9.73MB 下载

iframe去边框问题

2012年05月08日 9KB 下载

Html_的table_边框设置

2011年03月04日 24KB 下载

没有更多推荐了,返回首页

不良信息举报

设置边框

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭