List of usage examples for javax.swing JButton setMargin
@BeanProperty(visualUpdate = true, description = "The space between the button's border and the label.") public void setMargin(Insets m)
From source file:Main.java
public static void main(String[] argv) throws Exception { JToolBar toolbar = new JToolBar(); ImageIcon icon = new ImageIcon("icon.gif"); Action action = new AbstractAction("Button Label", icon) { public void actionPerformed(ActionEvent evt) { }/* ww w .j a v a 2 s . c om*/ }; JButton c1 = new JButton(action); c1.setText(null); c1.setMargin(new Insets(0, 0, 0, 0)); toolbar.add(c1); JToggleButton c2 = new JToggleButton(action); c2.setText(null); c2.setMargin(new Insets(0, 0, 0, 0)); toolbar.add(c2); JComboBox c3 = new JComboBox(new String[] { "A", "B", "C" }); c3.setPrototypeDisplayValue("XXXXXXXX"); // Set a desired width c3.setMaximumSize(c3.getMinimumSize()); toolbar.add(c3); }
From source file:Main.java
public static void adjustButtonMargins(Insets margin, JButton... buttons) { for (JButton button : buttons) button.setMargin(margin); }
From source file:Main.java
/** * @param label//from ww w .ja va 2s .co m * @param icon * @return createb JButton used in toolbar */ public static JButton createToolbarButton(String label, Icon icon) { JButton button = new JButton(icon); button.setFocusPainted(false); button.setMargin(new Insets(0, 0, 0, 0)); button.setToolTipText(label); button.setActionCommand(label); return button; }
From source file:Main.java
/** * @param label/*from w w w .j ava2 s. co m*/ * @param iconFileName * @return createb JButton used in toolbar */ public static JButton createToolbarButton(String label, String iconFileName) { JButton button = new JButton(new ImageIcon(iconFileName)); button.setFocusPainted(false); button.setMargin(new Insets(0, 0, 0, 0)); button.setToolTipText(label); button.setActionCommand(label); return button; }
From source file:Main.java
/** * Returns a styled JButton.//w w w. j a va 2 s . co m * * @param style button type * @return a styled button */ public static JButton creaStyledButton(int style) { JButton jb = new JButton(); jb.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); jb.setMargin(new Insets(0, 5, 1, 5)); switch (style) { case STYLE_EDIT: { jb.setText("edit"); jb.setToolTipText("edit"); jb.setPreferredSize(new Dimension(60, 30)); return jb; } case STYLE_OK: { jb.setText("ok"); jb.setToolTipText("confirm changes"); jb.setPreferredSize(new Dimension(60, 30)); return jb; } case STYLE_CANCEL: { jb.setText("cancel"); jb.setToolTipText("discard changes"); jb.setPreferredSize(new Dimension(60, 30)); return jb; } case STYLE_INSBEFOREROW: { jb.setIcon(ICON_INSBEFOREROW); jb.setToolTipText("insert row before"); jb.setName("INSBEFOREROW"); return jb; } case STYLE_INSAFTERROW: { jb.setIcon(ICON_INSAFTERROW); jb.setToolTipText("insert row after"); jb.setName("INSAFTERROW"); return jb; } case STYLE_DELETEROW: { jb.setIcon(ICON_DELETEROW); jb.setToolTipText("delete row"); jb.setName("DELETEROW"); return jb; } case STYLE_CLONEBEFOREROW: { jb.setIcon(ICON_CLONEBEFOREROW); jb.setToolTipText("clone row before"); jb.setName("CLONEBEFOREROW"); return jb; } case STYLE_CLONEAFTERROW: { jb.setIcon(ICON_CLONEAFTERROW); jb.setToolTipText("clone row after"); jb.setName("CLONEAFTERROW"); return jb; } case STYLE_DEFAULTROWS: { jb.setIcon(ICON_DEFAULTROWS); jb.setToolTipText("set default values"); jb.setName("DEFAULTROWS"); return jb; } default: { return null; } } }
From source file:Main.java
/** * Configures a button as if it was an hyperlink. * //from w ww.j ava2 s .c o m * @param button * the button to configure. */ public static void configureButtonAsHyperlink(JButton button) { if (button == null) { return; } StringBuffer html = new StringBuffer(); html.append("<html><font color=\"blue\"><u>"); html.append(button.getText()); html.append("</u></font></html>"); button.setText(html.toString()); button.setMargin(new Insets(0, 0, 0, 0)); button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); button.setFocusPainted(false); button.setBorderPainted(false); button.setContentAreaFilled(false); }
From source file:net.sf.texprinter.utils.UIUtils.java
/** * Formats a button to a label with wider margins. In short, this * method is similar to the button/label one, but with wider margins. * * @param button The button. Nothing new here. *//*from w ww.ja va2 s.c o m*/ public static void formatButtonAsList(JButton button) { // disable focus paint button.setFocusPainted(false); // fix the margins button.setMargin(new Insets(0, 0, 0, 5)); // disable content area fill button.setContentAreaFilled(false); // disable border paint button.setBorderPainted(false); // disable property button.setOpaque(false); }
From source file:net.sf.texprinter.utils.UIUtils.java
/** * Formats a JButton as a JLabel. In some cases, I just want the a * JButton component to act as a JLabel, so this method does this * for me.//from www . j a v a 2 s . c o m * * @param button The button. Some makeup is made to the button, so * it will look as a good old JLabel component. */ public static void formatButtonAsLabel(JButton button) { // disable focus paint button.setFocusPainted(false); // redefine margins button.setMargin(new Insets(0, 0, 0, 0)); // disable content area fill button.setContentAreaFilled(false); // disable border paint button.setBorderPainted(false); // disable property button.setOpaque(false); }
From source file:ButtonScroll.java
protected JButton createButton(String name, char mnemonics) { JButton btn = new JButton(name); btn.setToolTipText("Move " + name); btn.setBorderPainted(false);/*from w w w .j a va2s .c om*/ btn.setMargin(new Insets(0, 0, 0, 0)); btn.setContentAreaFilled(false); btn.setMnemonic(mnemonics); return btn; }
From source file:NwFontChooserS.java
private void addButtons() { JButton ok = new JButton("OK"); ok.setMargin(new Insets(0, 0, 0, 0)); JButton ca = new JButton("Cancel"); ca.setMargin(new Insets(0, 0, 0, 0)); ok.setBounds(260, 350, 70, 20);/* w w w . jav a 2 s . c om*/ ok.setFont(new Font(" ", 1, 11)); ca.setBounds(340, 350, 70, 20); ca.setFont(new Font(" ", 1, 12)); getContentPane().add(ok); getContentPane().add(ca); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); ob = true; } }); ca.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); ob = false; } }); }