List of usage examples for javax.swing AbstractButton setIcon
@BeanProperty(visualUpdate = true, description = "The button's default icon") public void setIcon(Icon defaultIcon)
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JButton("Press Me"); jb.setIcon(new MyIcon()); jb.setIconTextGap(50);//from w w w . j a v a 2 s . c om JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JToggleButton("Press Me"); jb.setIcon(new MyIcon()); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb);/* ww w . ja v a2 s . c om*/ f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JToggleButton("Press Me"); jb.setHorizontalTextPosition(20);/*from w ww.j a v a 2 s . com*/ jb.setIcon(new MyIcon()); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { AbstractButton jb = new JToggleButton("Press Me"); jb.setHorizontalAlignment(SwingConstants.RIGHT); jb.setIcon(new MyIcon()); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb);/* w w w . ja v a 2s. c om*/ f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);/*from www. j av a2 s. c o m*/ // File->New, N - Mnemonic JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N); fileMenu.add(newMenuItem); JCheckBoxMenuItem caseMenuItem = new JCheckBoxMenuItem("Case Sensitive"); caseMenuItem.setMnemonic(KeyEvent.VK_C); fileMenu.add(caseMenuItem); ItemListener iListener = new ItemListener() { public void itemStateChanged(ItemEvent event) { Icon girlIcon = new ImageIcon("g.jpg"); Icon boyIcon = new ImageIcon("b.jpg"); AbstractButton aButton = (AbstractButton) event.getSource(); int state = event.getStateChange(); String newLabel; Icon newIcon; if (state == ItemEvent.SELECTED) { newLabel = "Girl"; newIcon = girlIcon; } else { newLabel = "Boy"; newIcon = boyIcon; } aButton.setText(newLabel); aButton.setIcon(newIcon); } }; caseMenuItem.addItemListener(iListener); frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:JCheckBoxMenuItemActionListener.java
public static void main(final String args[]) { JFrame frame = new JFrame("MenuSample Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu);/*from ww w . j a v a2s .c o m*/ // File->New, N - Mnemonic JMenuItem newMenuItem = new JMenuItem("New", KeyEvent.VK_N); fileMenu.add(newMenuItem); JCheckBoxMenuItem caseMenuItem = new JCheckBoxMenuItem("Case Sensitive"); caseMenuItem.setMnemonic(KeyEvent.VK_C); fileMenu.add(caseMenuItem); ItemListener iListener = new ItemListener() { public void itemStateChanged(ItemEvent event) { Icon girlIcon = new ImageIcon("girl-r.jpg"); Icon boyIcon = new ImageIcon("boy-r.jpg"); AbstractButton aButton = (AbstractButton) event.getSource(); int state = event.getStateChange(); String newLabel; Icon newIcon; if (state == ItemEvent.SELECTED) { newLabel = "Girl"; newIcon = girlIcon; } else { newLabel = "Boy"; newIcon = boyIcon; } aButton.setText(newLabel); aButton.setIcon(newIcon); } }; caseMenuItem.addItemListener(iListener); frame.setJMenuBar(menuBar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:CheckBoxSample.java
public static void main(String args[]) { ActionListener aListener = new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); boolean selected = aButton.getModel().isSelected(); String newLabel;/*from w w w .j a va 2s.c om*/ Icon newIcon; if (selected) { newLabel = "Girl"; newIcon = girlIcon; } else { newLabel = "Boy"; newIcon = boyIcon; } aButton.setText(newLabel); aButton.setIcon(newIcon); } }; ItemListener iListener = new ItemListener() { public void itemStateChanged(ItemEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); int state = event.getStateChange(); String newLabel; Icon newIcon; if (state == ItemEvent.SELECTED) { newLabel = "Girl"; newIcon = girlIcon; } else { newLabel = "Boy"; newIcon = boyIcon; } aButton.setText(newLabel); aButton.setIcon(newIcon); } }; JFrame frame = new JFrame("CheckBox Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("Menu"); menu.setMnemonic(KeyEvent.VK_M); JCheckBoxMenuItem one = new JCheckBoxMenuItem(); menu.add(one); JCheckBoxMenuItem two = new JCheckBoxMenuItem("Boy"); menu.add(two); JCheckBoxMenuItem three = new JCheckBoxMenuItem(boyIcon); menu.add(three); JCheckBoxMenuItem four = new JCheckBoxMenuItem("Girl", true); menu.add(four); JCheckBoxMenuItem five = new JCheckBoxMenuItem("Boy", boyIcon); five.addItemListener(iListener); menu.add(five); Icon stateIcon = new DiamondAbstractButtonStateIcon(Color.black); UIManager.put("CheckBoxMenuItem.checkIcon", stateIcon); JCheckBoxMenuItem six = new JCheckBoxMenuItem("Girl", girlIcon, true); six.addActionListener(aListener); menu.add(six); bar.add(menu); frame.setJMenuBar(bar); frame.setSize(350, 250); frame.setVisible(true); }
From source file:com.projity.menu.ExtToolBarFactory.java
public AbstractButton createJButton(String name) throws MissingResourceException, ResourceFormatException, MissingListenerException { AbstractButton button = super.createJButton(name); try {/*from ww w . j a va2 s . c o m*/ String s = getString(name + ExtMenuFactory.ICON_SUFFIX); ImageIcon icon = IconManager.getIcon(s); if (icon != null) button.setIcon(icon); } catch (MissingResourceException e) { } String actionName = getActionStringFromId(name); if (actionName != null) toolButtons.put(actionName, button); button.setActionCommand(name); return button; }
From source file:MainClass.java
public boolean importData(JComponent comp, Transferable t) { if (comp instanceof JLabel) { JLabel label = (JLabel) comp; if (t.isDataFlavorSupported(flavors[0])) { try { image = (Image) t.getTransferData(flavors[0]); ImageIcon icon = new ImageIcon(image); label.setIcon(icon);/* w w w.j a v a 2s . c o m*/ return true; } catch (UnsupportedFlavorException ignored) { } catch (IOException ignored) { } } } else if (comp instanceof AbstractButton) { AbstractButton button = (AbstractButton) comp; if (t.isDataFlavorSupported(flavors[0])) { try { image = (Image) t.getTransferData(flavors[0]); ImageIcon icon = new ImageIcon(image); button.setIcon(icon); return true; } catch (UnsupportedFlavorException ignored) { } catch (IOException ignored) { } } } return false; }
From source file:hr.fer.zemris.vhdllab.view.explorer.ProjectExplorerView.java
private AbstractButton createHierarchyButton(ActionCommand command) { AbstractButton button = command.createButton(); button.setText(null);/*w ww. j a va 2 s.c o m*/ String iconKey = BeanUtil.beanName(command.getClass()) + ".bigicon"; button.setIcon(getIconSource().getIcon(iconKey)); return button; }