public int getDisclosureStateCount() { Integer value = (Integer) disclosureButton.getClientProperty(DisclosureIcon.STATE_COUNT_PROPERTY); return (value == null) ? 2 : value; }
public int getDisclosureState() { Integer value = (Integer) disclosureButton.getClientProperty(DisclosureIcon.CURRENT_STATE_PROPERTY); return (value == null) ? 1 : value; }
JButton button = (JButton)e.getSource(); Color color = (Color)button.getClientProperty("color"); panel.setBackground( color );
JButton button = (JButton) actionEvent.getSource(); Integer firstIndex = button.getClientProperty( "firstIndex" ); Integer secondIndex = button.getClientProperty( "secondIndex" );
JButton button = ae.getSource(); int value = button.getClientProperty("Which").intValue();
public class MyActionListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { JButton btn = (JButton) e.getSource(); System.out.println("clicked column " + btn.getClientProperty("column") + ", row " + btn.getClientProperty("row")); }
public static boolean isSquare(Component c) { if (c instanceof JButton) { JButton b = (JButton) c; return "square".equals(b.getClientProperty("JButton.buttonType")); } return false; }
public class MyActionListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { JButton btn = (JButton) e.getSource(); System.out.println("clicked column " + btn.getClientProperty("column") + ", row " + btn.getClientProperty("row")); }
public class MyActionListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { JButton btn = (JButton) e.getSource(); System.out.println("clicked column " + btn.getClientProperty("column") + ", row " + btn.getClientProperty("row")); }
public class MyActionListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { JButton btn = (JButton) e.getSource(); System.out.println("clicked column " + btn.getClientProperty("column") + ", row " + btn.getClientProperty("row")); }
btn.putClientProperty("value", 1); public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source instanceof JButton) { JButton btn = (JButton)source; value = (Integer)btn.getClientProperty("value");
public class MyActionListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { JButton btn = (JButton) e.getSource(); System.out.println("clicked column " + btn.getClientProperty("column") + ", row " + btn.getClientProperty("row")); }
private static final String EVENT_TYPE = "event_type"; // button creation normalSetupButton = new JButton(); // set appropriate event for this button normalSetupButton.putClientProperty(EVENT_TYPE, SimulationEvent.NORMAL_SETUP_EVENT); // other init button routine //next button queenTestButton = new JButton(); queenTestButton.putClientProperty(EVENT_TYPE, SimulationEvent.QUEEN_TEST_EVENT); // other init button routine // same way for other buttons public void actionPerformed(ActionEvent e) { // get the button that was pressed JButton b = (JButton) e.getSource(); SimulationEvent evt = (SimulationEvent) b.getClientProperty(EVENT_TYPE); fireSimulationEvent(evt); }
@Override public void actionPerformed(ActionEvent e) { int newState = ((Integer) disclosureButton.getClientProperty(DisclosureIcon.CURRENT_STATE_PROPERTY) + 1) % (Integer) disclosureButton.getClientProperty(DisclosureIcon.STATE_COUNT_PROPERTY); setDisclosureState(newState); } });
JButton j = new JButton("click here"); j.putClientProperty("id", "employee1"); j.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { JButton source = (JButton)ae.getSource(); String id = (String) source.getClientProperty("id"); System.out.print(id); } });
@Override public void actionPerformed(ActionEvent ae) { if (ae.getSource() instanceof JButton) { JButton button = (JButton) ae.getSource(); Solution solution = (Solution) button.getClientProperty("Solution"); // NOI18N solution.resolve().run(); button.setEnabled(false); } } }
/** This takes a set of buttons and gives them all the width/height * of the largest button among them. * <P>(More specifically, this sets the <code>preferredSize</code> * of each button to the largest preferred size in the list of buttons. * * @param buttons an array of buttons. */ public static void normalizeButtons(JButton[] buttons) { int maxWidth = 0; int maxHeight = 0; for(int a = 0; a<buttons.length; a++) { buttons[a].setPreferredSize(null); Dimension d = buttons[a].getPreferredSize(); Number n = (Number)buttons[a].getClientProperty( DialogFooter.PROPERTY_OPTION ); if( (n!=null && n.intValue()==DialogFooter.DONT_SAVE_OPTION) || d.width>80 ) { buttons[a] = null; } if(buttons[a]!=null) { maxWidth = Math.max(d.width, maxWidth); maxHeight = Math.max(d.height, maxHeight); } } for(int a = 0; a<buttons.length; a++) { if(buttons[a]!=null) buttons[a].setPreferredSize(new Dimension(maxWidth,maxHeight)); } }
/** Finds a certain type of button, if it is available. * * @param buttonType of the options in this class (such as YES_OPTION or CANCEL_OPTION) * @return the button that maps to that option, or null if no such button was found. */ public JButton getButton(int buttonType) { for(int a = 0; a<getComponentCount(); a++) { if(getComponent(a) instanceof JButton) { JButton button = (JButton)getComponent(a); Object value = button.getClientProperty(PROPERTY_OPTION); int intValue = -1; if(value instanceof Number) intValue = ((Number)value).intValue(); if(intValue==buttonType) return button; } } return null; }
final Action deleteAction = new AbstractAction("Delete") { @Override public void actionPerformed(ActionEvent e) { JButton button = (JButton)e.getSource(); JTextField textField = (JTextField)button.getClientProperty("AssociatedTextField"); if (textField != null) { JComponent parentContainer = (JComponent)button.getParent(); parentContainer.remove(button); parentContainer.remove(textField); parentContainer.revalidate(); parentContainer.repaint(); SwingUtilities.windowForComponent(parentContainer).pack(); } } };
private void setRootPaneContainer(JButton button,RootPaneContainer c) { RootPaneContainer lastContainer = (RootPaneContainer)button.getClientProperty("bric.footer.rpc"); if(lastContainer==c) return; if(lastContainer!=null) { lastContainer.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).remove(escapeKey); lastContainer.getRootPane().getActionMap().remove(escapeKey); if(JVM.isMac) lastContainer.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).remove(commandPeriodKey); } if(c!=null) { c.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(escapeKey, escapeKey); c.getRootPane().getActionMap().put(escapeKey, new ClickAction(button)); if(JVM.isMac) c.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(commandPeriodKey, escapeKey); } button.putClientProperty("bric.footer.rpc", c); }