List of utility methods to do JButton Create
JComponent | createButtonRow(List buttons) Takes the given list of buttons and creates a horizontal panel containing them, with standard spacing and size. equalizeSizes(buttons); Box row = new Box(BoxLayout.X_AXIS); row.setBorder(BorderFactory.createEmptyBorder(DEFAULT_BORDER, 0, DEFAULT_BORDER, 0)); Iterator buttonIt = buttons.iterator(); while (buttonIt.hasNext()) { row.add((JComponent) buttonIt.next()); if (buttonIt.hasNext()) row.add(Box.createRigidArea(new Dimension(DEFAULT_STRUT, 0))); ... |
JPanel | createButtonsPanel(JComponent... components) create Buttons Panel final JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonsPanel.setOpaque(false); for (final JComponent component : components) { buttonsPanel.add(component); return buttonsPanel; |
JPanel | createCheckbox(String boxlabel, String[] buttons, boolean[] checked, ActionListener al) Create a panel containing a checkbox. JPanel jp = createPaletteJPanel(boxlabel); for (int j = 0; j < buttons.length; j++) { JCheckBox jcb = new JCheckBox(buttons[j]); jcb.setActionCommand(Integer.toString(j)); if (al != null) jcb.addActionListener(al); jcb.setSelected(checked[j]); jp.add(jcb); ... |
JButton | createCustomButton(Action a) create Custom Button return (JButton) customize(new JButton(a)); |
JButton | CreateFlatButton() Creates a new JButton with the flat appearance. JButton button = new JButton(); makeButtonFlat(button); return button; |
JRadioButton | createGameRadioButton(String answer, int fontSize) create Game Radio Button JRadioButton btn = new JRadioButton(answer); btn.setBackground(Color.GRAY); btn.setForeground(Color.WHITE); btn.setFont(new Font(" ", Font.BOLD, fontSize)); return btn; |
JButton | createHyperlinkButton(String text, String tip, ActionListener action) create Hyperlink Button JButton button = new JButton(); button.setText("<html><a href=\"#\">" + text + "</a></html>"); button.setHorizontalAlignment(SwingConstants.LEFT); button.setBorderPainted(false); button.setBorder(BorderFactory.createEmptyBorder()); button.setOpaque(false); button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); button.setBackground(new Color(0, 0, 0, 0)); ... |
JButton | createIconButton(Class> klass, String resource, String fallbackText) Creates a JButton with an Icon from the named resource, which should be in the class loader jar file as klass .
JButton result = new JButton(); try { Image image = ImageIO.read(klass.getResource(resource)); result.setIcon(new ImageIcon(image)); } catch (Exception e) { result.setText(fallbackText); result.setToolTipText(fallbackText); ... |
JButton | createIconButton(ImageIcon icon, int dimension, String tooltipText, java.awt.event.ActionListener action) create Icon Button JButton btn = new JButton(); btn.setToolTipText(tooltipText); btn.setIcon(icon); btn.setMaximumSize(new Dimension(dimension, dimension)); btn.setMinimumSize(new Dimension(dimension, dimension)); btn.setPreferredSize(new Dimension(dimension, dimension)); btn.setMargin(new Insets(0, 0, 0, 0)); if (action != null) ... |
JButton | createJButton(Container c, String caption, int x, int y, int width, int height, ActionListener al) This method makes it easy (and also neat) creating a JButton and adding it to its container class.
JButton btn = new JButton(caption); btn.setBounds(x, y, width, height); if (al != null) btn.addActionListener(al); c.add(btn); return btn; |