List of usage examples for javax.swing JPanel setBorder
@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.") public void setBorder(Border border)
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); 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);//from w w w . java 2s. c o m 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:OverlaySample.java
public static void main(String args[]) { ActionListener generalActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JComponent comp = (JComponent) actionEvent.getSource(); System.out.println(actionEvent.getActionCommand() + ": " + comp.getBounds()); }//from w ww .j a v a 2 s . co m }; ActionListener sizingActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { setupButtons(actionEvent.getActionCommand()); } }; JFrame frame = new JFrame("Overlay Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); LayoutManager overlay = new OverlayLayout(panel); panel.setLayout(overlay); Object settings[][] = { { "Small", new Dimension(25, 25), Color.white }, { "Medium", new Dimension(50, 50), Color.gray }, { "Large", new Dimension(100, 100), Color.black } }; JButton buttons[] = { smallButton, mediumButton, largeButton }; for (int i = 0, n = settings.length; i < n; i++) { JButton button = buttons[i]; button.addActionListener(generalActionListener); button.setActionCommand((String) settings[i][0]); button.setMaximumSize((Dimension) settings[i][1]); button.setBackground((Color) settings[i][2]); panel.add(button); } setupButtons(SET_CENTRAL); JPanel actionPanel = new JPanel(); actionPanel.setBorder(BorderFactory.createTitledBorder("Change Alignment")); String actionSettings[] = { SET_MINIMUM, SET_MAXIMUM, SET_CENTRAL, SET_MIXED }; for (int i = 0, n = actionSettings.length; i < n; i++) { JButton button = new JButton(actionSettings[i]); button.addActionListener(sizingActionListener); actionPanel.add(button); } Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(actionPanel, BorderLayout.SOUTH); frame.setSize(400, 300); frame.setVisible(true); }
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); 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; }/*from w w w. j a v a 2s .co m*/ } 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: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); 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; }/* ww w .j a v a 2 s. c o m*/ } 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:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.pack();/* ww w.j a v a 2 s.c o m*/ Container contentPane = frame.getContentPane(); contentPane.setLayout(null); for (int i = 0; i < 4; i++) { JPanel panel = new JPanel(); panel.setBounds((i * 75) + 475, 25, 75, 100); System.out.println(panel.getBounds()); contentPane.add(panel); panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 3)); } System.out.println(getComponentAt(contentPane, new Point(475, 25))); System.out.println(getComponentAt(contentPane, new Point(100, 25))); frame.setVisible(true); }
From source file:BorderExample.java
public static void main(String[] args) { JPanel panel = new JPanel(new BorderLayout()); JPanel top = new JPanel(); top.setBackground(Color.gray); top.setPreferredSize(new Dimension(250, 150)); panel.add(top);/*from w w w . j a v a2 s .c o m*/ panel.setBorder(new EmptyBorder(new Insets(10, 20, 30, 40))); JFrame f = new JFrame(); f.add(panel); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }
From source file:OvalBorder.java
public static void main(String[] s) { JFrame f = new JFrame("Oval Border"); f.setSize(100, 100);//from w w w. j a va 2s.c o m JPanel p = new JPanel(new GridLayout(0, 1, 5, 5)); JLabel l = new JLabel("Oval Border"); l.setBorder(new OvalBorder()); p.add(l); p.setBorder(new OvalBorder()); f.getContentPane().add(p); f.show(); }
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. j a va 2s .co m frame.getContentPane().add(b); frame.pack(); 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 gui = new JPanel(new BorderLayout(5, 5)); JPanel plafComponents = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 3)); plafComponents.setBorder(new TitledBorder("FlowLayout(FlowLayout.RIGHT, 3,3)")); UIManager.LookAndFeelInfo[] plafInfos = UIManager.getInstalledLookAndFeels(); String[] plafNames = new String[plafInfos.length]; for (int ii = 0; ii < plafInfos.length; ii++) { plafNames[ii] = plafInfos[ii].getName(); }/*from w w w. j av a 2 s. c o m*/ JComboBox plafChooser = new JComboBox(plafNames); plafComponents.add(plafChooser); JCheckBox pack = new JCheckBox("Pack on PLAF change", true); plafComponents.add(pack); plafChooser.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int index = plafChooser.getSelectedIndex(); try { UIManager.setLookAndFeel(plafInfos[index].getClassName()); SwingUtilities.updateComponentTreeUI(frame); if (pack.isSelected()) { frame.pack(); frame.setMinimumSize(frame.getSize()); } } catch (Exception e) { e.printStackTrace(); } } }); gui.add(plafComponents, BorderLayout.NORTH); JPanel dynamicLabels = new JPanel(new BorderLayout(4, 4)); dynamicLabels.setBorder(new TitledBorder("BorderLayout(4,4)")); gui.add(dynamicLabels, BorderLayout.WEST); final JPanel labels = new JPanel(new GridLayout(0, 2, 3, 3)); labels.setBorder(new TitledBorder("GridLayout(0,2,3,3)")); JButton addNew = new JButton("Add Another Label"); dynamicLabels.add(addNew, BorderLayout.NORTH); addNew.addActionListener(new ActionListener() { private int labelCount = 0; public void actionPerformed(ActionEvent ae) { labels.add(new JLabel("Label " + ++labelCount)); frame.validate(); } }); dynamicLabels.add(new JScrollPane(labels), BorderLayout.CENTER); String[] header = { "Name", "Value" }; String[] a = new String[0]; String[] names = System.getProperties().stringPropertyNames().toArray(a); String[][] data = new String[names.length][2]; for (int ii = 0; ii < names.length; ii++) { data[ii][0] = names[ii]; data[ii][1] = System.getProperty(names[ii]); } DefaultTableModel model = new DefaultTableModel(data, header); JTable table = new JTable(model); JScrollPane tableScroll = new JScrollPane(table); Dimension tablePreferred = tableScroll.getPreferredSize(); tableScroll.setPreferredSize(new Dimension(tablePreferred.width, tablePreferred.height / 3)); JPanel imagePanel = new JPanel(new GridBagLayout()); JLabel imageLabel = new JLabel("test"); imagePanel.add(imageLabel, null); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tableScroll, new JScrollPane(imagePanel)); gui.add(splitPane, BorderLayout.CENTER); frame.setContentPane(gui); frame.pack(); frame.setVisible(true); }
From source file:DocumentModel.java
public static void main(String[] args) { final StyledDocument doc; final JTextPane textpane; JFrame f = new JFrame(); f.setTitle("Document Model"); JToolBar toolbar = new JToolBar(); JButton boldb = new JButton("bold"); JButton italb = new JButton("italic"); JButton strib = new JButton("strike"); JButton undeb = new JButton("underline"); toolbar.add(boldb);/*from ww w . ja v a 2s . c o m*/ toolbar.add(italb); toolbar.add(strib); toolbar.add(undeb); f.add(toolbar, BorderLayout.NORTH); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); JScrollPane pane = new JScrollPane(); textpane = new JTextPane(); textpane.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); doc = textpane.getStyledDocument(); Style style = textpane.addStyle("Bold", null); StyleConstants.setBold(style, true); style = textpane.addStyle("Italic", null); StyleConstants.setItalic(style, true); style = textpane.addStyle("Underline", null); StyleConstants.setUnderline(style, true); style = textpane.addStyle("Strike", null); StyleConstants.setStrikeThrough(style, true); boldb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doc.setCharacterAttributes(textpane.getSelectionStart(), textpane.getSelectionEnd() - textpane.getSelectionStart(), textpane.getStyle("Bold"), false); } }); italb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doc.setCharacterAttributes(textpane.getSelectionStart(), textpane.getSelectionEnd() - textpane.getSelectionStart(), textpane.getStyle("Italic"), false); } }); strib.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doc.setCharacterAttributes(textpane.getSelectionStart(), textpane.getSelectionEnd() - textpane.getSelectionStart(), textpane.getStyle("Strike"), false); } }); undeb.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doc.setCharacterAttributes(textpane.getSelectionStart(), textpane.getSelectionEnd() - textpane.getSelectionStart(), textpane.getStyle("Underline"), false); } }); pane.getViewport().add(textpane); panel.add(pane); f.add(panel); f.setSize(new Dimension(380, 320)); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); }