List of usage examples for javax.swing BorderFactory createTitledBorder
public static TitledBorder createTitledBorder(Border border)
From source file:Main.java
public static void main(String args[]) { JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Examples"); panel.setBorder(border);//from w w w. j a v a2 s .co m ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JToggleButton("Toggle Button"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Radio Button"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JCheckBox("Check Box"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item"); panel.add(abstract5); group.add(abstract5); JFrame frame = new JFrame("Button Group"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS)); JPanel a = new JPanel(); a.setAlignmentX(Component.CENTER_ALIGNMENT); a.setPreferredSize(new Dimension(100, 100)); a.setMaximumSize(new Dimension(100, 100)); // set max = pref a.setBorder(BorderFactory.createTitledBorder("aa")); JPanel b = new JPanel(); b.setAlignmentX(Component.CENTER_ALIGNMENT); b.setPreferredSize(new Dimension(50, 50)); b.setMaximumSize(new Dimension(50, 50)); // set max = pref b.setBorder(BorderFactory.createTitledBorder("bb")); frame.getContentPane().add(a);//from w w w . jav a 2s .c o m frame.getContentPane().add(b); frame.pack(); frame.setVisible(true); }
From source file:JColorChooserSample.java
public static void main(String args[]) { JFrame frame = new JFrame("JColorChooser Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JLabel label = new JLabel("www.java2s.com", JLabel.CENTER); label.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48)); frame.add(label, BorderLayout.SOUTH); final JColorChooser colorChooser = new JColorChooser(label.getBackground()); colorChooser.setBorder(BorderFactory.createTitledBorder("Pick Foreground Color")); frame.add(colorChooser, BorderLayout.CENTER); frame.pack();/*w ww . j a va 2s .c o m*/ frame.setVisible(true); }
From source file:AButtonGroup.java
public static void main(String args[]) { JFrame frame = new JFrame("Button Group"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Examples"); panel.setBorder(border);// w ww. j av a2 s . c o m ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JToggleButton("Toggle Button"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Radio Button"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JCheckBox("Check Box"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item"); panel.add(abstract5); group.add(abstract5); frame.add(panel, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:AButtonGroup.java
public static void main(String args[]) { JFrame frame = new JFrame("Button Group"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Examples"); panel.setBorder(border);/* w w w . j a v a 2 s.com*/ ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JToggleButton("Toggle Button"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Radio Button"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JCheckBox("Check Box"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item"); panel.add(abstract5); group.add(abstract5); Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Options"); panel.setBorder(border);//from w w w.j ava 2s .c o m final ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JRadioButton("One"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Two"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JRadioButton("Three"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButton("Four"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JRadioButton("Five"); panel.add(abstract5); group.add(abstract5); ActionListener aListener = new ActionListener() { public void actionPerformed(ActionEvent event) { Enumeration elements = group.getElements(); while (elements.hasMoreElements()) { AbstractButton button = (AbstractButton) elements.nextElement(); if (button.isSelected()) { System.out.println("The winner is: " + button.getText()); break; } } group.setSelected(null, true); } }; JButton button = new JButton("Show Selected"); button.addActionListener(aListener); Container container = frame.getContentPane(); container.add(panel, BorderLayout.CENTER); container.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:FindingAButtonGroup.java
public static void main(String args[]) { JFrame frame = new JFrame("Button Group"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Examples"); panel.setBorder(border);/*ww w. j a va2s . c o m*/ ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JToggleButton("Toggle Button"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Radio Button"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JCheckBox("Check Box"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item"); panel.add(abstract5); group.add(abstract5); frame.add(panel, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); group.setSelected(abstract1.getModel(), true); Enumeration elements = group.getElements(); while (elements.hasMoreElements()) { AbstractButton button = (AbstractButton) elements.nextElement(); if (button.isSelected()) { System.out.println("The winner is: " + button.getText()); } } }
From source file:ASelectedButton.java
public static void main(String args[]) { JFrame frame = new JFrame("Radio Buttons"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Options"); panel.setBorder(border);// www . j a va 2 s .c om final ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JRadioButton("One"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Two"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JRadioButton("Three"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButton("Four"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JRadioButton("Five"); panel.add(abstract5); group.add(abstract5); ActionListener aListener = new ActionListener() { public void actionPerformed(ActionEvent event) { Enumeration elements = group.getElements(); while (elements.hasMoreElements()) { AbstractButton button = (AbstractButton) elements.nextElement(); if (button.isSelected()) { System.out.println("The winner is: " + button.getText()); break; } } group.setSelected(null, true); } }; JToggleButton button = new JToggleButton("Show Selected"); button.addActionListener(aListener); Container container = frame.getContentPane(); container.add(panel, BorderLayout.CENTER); container.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:SettingSelectedAButtonGroup.java
public static void main(String args[]) { JFrame frame = new JFrame("Button Group"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Examples"); panel.setBorder(border);//from w w w . jav a 2s.c o m ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JToggleButton("Toggle Button"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Radio Button"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JCheckBox("Check Box"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButtonMenuItem("Radio Button Menu Item"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JCheckBoxMenuItem("Check Box Menu Item"); panel.add(abstract5); group.add(abstract5); frame.add(panel, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); group.setSelected(abstract1.getModel(), true); Enumeration elements = group.getElements(); while (elements.hasMoreElements()) { AbstractButton button = (AbstractButton) elements.nextElement(); if (button.isSelected()) { System.out.println("The winner is: " + button.getText()); } } }
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("JColorChooser Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JLabel label = new JLabel("www.java2s.com", JLabel.CENTER); label.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 48)); frame.add(label, BorderLayout.SOUTH); final JColorChooser colorChooser = new JColorChooser(label.getBackground()); colorChooser.setBorder(BorderFactory.createTitledBorder("Pick Color for java2s.com")); ColorSelectionModel model = colorChooser.getSelectionModel(); ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { Color newForegroundColor = colorChooser.getColor(); label.setForeground(newForegroundColor); }/*from ww w . j a v a 2 s .c om*/ }; model.addChangeListener(changeListener); frame.add(colorChooser, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }