import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.*;
public class BorderTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
EventQueue.invokeLater(new Runnable() {
public void run(){
BorderFrame frame = new BorderFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
});
}
}
class BorderFrame extends JFrame {
private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 200;
private JPanel demoPanel;
private JPanel btnPanel;
private ButtonGroup group;
public BorderFrame() {
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
setTitle("BorderFrame");
demoPanel = new JPanel();
btnPanel = new JPanel();
group = new ButtonGroup();
addRadioBtn("Lower bevel", BorderFactory.createLoweredBevelBorder());
addRadioBtn("Raise bevel", BorderFactory.createRaisedBevelBorder());
addRadioBtn("Etched bevel", BorderFactory.createEtchedBorder());
Border etched = BorderFactory.createEtchedBorder();
Border titled = BorderFactory.createTitledBorder(etched, "Border types");
btnPanel.setBorder(titled);
setLayout(new GridLayout(2, 1));
add(btnPanel);
add(demoPanel);
}
public void addRadioBtn(String name, final Border b) {
JRadioButton radioBtn = new JRadioButton(name);
radioBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
demoPanel.setBorder(b);
}
});
group.add(radioBtn);
btnPanel.add(radioBtn);
}
}