List of usage examples for javax.swing JButton setFocusable
public void setFocusable(boolean focusable)
From source file:ActionFocusMover.java
public static void main(String args[]) { JFrame frame = new JFrame("Focus Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener actionListener = new ActionFocusMover(); frame.setLayout(new GridLayout(3, 3)); for (int i = 1; i < 10; i++) { JButton button = new JButton(Integer.toString(i)); button.addActionListener(actionListener); if ((i % 2) != 0) { button.setFocusable(false); }/*from w w w . j a v a 2s . c o m*/ frame.add(button); } frame.setSize(300, 200); frame.setVisible(true); }
From source file:MouseEnterFocusMover.java
public static void main(String args[]) { JFrame frame = new JFrame("Focus Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MouseListener mouseListener = new MouseEnterFocusMover(); frame.setLayout(new GridLayout(3, 3)); for (int i = 1; i < 10; i++) { JButton button = new JButton(Integer.toString(i)); button.addMouseListener(mouseListener); if ((i % 2) != 0) { button.setFocusable(false); }//ww w .ja va 2 s . co m frame.add(button); } frame.setSize(300, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Focus Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener actionListener = new ActionFocusMover(); MouseListener mouseListener = new MouseEnterFocusMover(); frame.setLayout(new GridLayout(3, 3)); for (int i = 1; i < 10; i++) { JButton button = new JButton(Integer.toString(i)); button.addActionListener(actionListener); button.addMouseListener(mouseListener); if ((i % 2) != 0) { button.setFocusable(false); }//from w w w. j a v a2 s. co m frame.add(button); } frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
/*************************************************************************** * Creates a {@link JButton} with settings that are common for toolbars. * /*from ww w . ja v a 2 s .c o m*/ * @param tooltip * @param icon * @return **************************************************************************/ public static JButton createToolbarButton(String tooltip, Icon icon) { JButton button = new JButton("", icon); button.setFocusable(false); button.setBorderPainted(false); button.setToolTipText(tooltip); return button; }
From source file:com.github.fritaly.dualcommander.DualCommander.java
private static JButton createButton(Action action) { Validate.notNull(action, "The given action is null"); final JButton button = new JButton(action); button.setFocusable(false); return button; }
From source file:com.haulmont.cuba.desktop.sys.WindowBreadCrumbs.java
public void update() { removeAll();/*from w w w .j ava 2 s.c o m*/ btn2win.clear(); for (Iterator<Window> it = windows.iterator(); it.hasNext();) { Window window = it.next(); JButton button = new JXHyperlink(); button.setFocusable(false); button.setText(StringUtils.trimToEmpty(window.getCaption())); button.addActionListener(new ValidationAwareActionListener() { @Override public void actionPerformedAfterValidation(ActionEvent e) { JButton btn = (JButton) e.getSource(); Window win = btn2win.get(btn); if (win != null) { fireListeners(win); } } }); btn2win.put(button, window); if (it.hasNext()) { add(button); JLabel separatorLab = new JLabel(">"); add(separatorLab); } else { add(new JLabel(window.getCaption())); } } }
From source file:lisong_mechlab.view.graphs.SustainedDpsGraph.java
/** * Creates and displays the {@link SustainedDpsGraph}. * //from w w w .j a va 2 s. c om * @param aLoadout * Which load out the diagram is for. * @param aXbar * A {@link MessageXBar} to listen for changes to the loadout on. * @param aMaxSustainedDpsMetric * A {@link MaxSustainedDPS} instance to use in calculation. */ public SustainedDpsGraph(LoadoutBase<?> aLoadout, MessageXBar aXbar, MaxSustainedDPS aMaxSustainedDpsMetric) { super("Max Sustained DPS over range for " + aLoadout); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); aXbar.attach(this); loadout = aLoadout; maxSustainedDPS = aMaxSustainedDpsMetric; chartPanel = new ChartPanel(makechart()); setContentPane(chartPanel); chartPanel.setLayout(new OverlayLayout(chartPanel)); JButton button = new JButton( new OpenHelp("What is this?", "Max-sustained-dps-graph", KeyStroke.getKeyStroke('w'))); button.setMargin(new Insets(5, 5, 5, 5)); button.setFocusable(false); button.setAlignmentX(Component.RIGHT_ALIGNMENT); button.setAlignmentY(Component.TOP_ALIGNMENT); chartPanel.add(button); setIconImage(ProgramInit.programIcon); setSize(800, 600); setVisible(true); }
From source file:lisong_mechlab.view.graphs.DamageGraph.java
/** * Creates and displays the {@link DamageGraph}. * /*from w ww. ja va 2 s . c om*/ * @param aLoadout * Which load out the diagram is for. * @param anXbar * A {@link MessageXBar} to listen for changes to the loadout on. * @param aMaxSustainedDpsMetric * A {@link MaxSustainedDPS} instance to use in calculation. */ public DamageGraph(LoadoutBase<?> aLoadout, MessageXBar anXbar, MaxSustainedDPS aMaxSustainedDpsMetric) { super("Max Sustained DPS over range for " + aLoadout); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); anXbar.attach(this); loadout = aLoadout; maxSustainedDPS = aMaxSustainedDpsMetric; chartPanel = new ChartPanel(makechart()); setContentPane(chartPanel); chartPanel.getChart().getLegend().setHorizontalAlignment(HorizontalAlignment.RIGHT); chartPanel.getChart().getLegend().setVerticalAlignment(VerticalAlignment.TOP); LegendTitle legendTitle = chartPanel.getChart().getLegend(); XYTitleAnnotation titleAnnotation = new XYTitleAnnotation(0.98, 0.98, legendTitle, RectangleAnchor.TOP_RIGHT); titleAnnotation.setMaxWidth(0.4); ((XYPlot) (chartPanel.getChart().getPlot())).addAnnotation(titleAnnotation); chartPanel.getChart().removeLegend(); chartPanel.setLayout(new OverlayLayout(chartPanel)); JButton button = new JButton( new OpenHelp("What is this?", "Max-sustained-dps-graph", KeyStroke.getKeyStroke('w'))); button.setMargin(new Insets(10, 10, 10, 10)); button.setFocusable(false); button.setAlignmentX(Component.RIGHT_ALIGNMENT); button.setAlignmentY(Component.BOTTOM_ALIGNMENT); chartPanel.add(button); setIconImage(ProgramInit.programIcon); setSize(800, 600); setVisible(true); }
From source file:it.iit.genomics.cru.igb.bundles.mi.business.MIWorker.java
/** * Adds a component to a JTabbedPane with a little close tab" button on the * right side of the tab.//from www . java 2 s . co m * * @param tabbedPane * the JTabbedPane * @param c * any JComponent * @param title * the title for the tab */ public static void addClosableTab(final JTabbedPane tabbedPane, final JComponent c, final String title) { // Add the tab to the pane without any label tabbedPane.addTab(null, c); int pos = tabbedPane.indexOfComponent(c); // Create a FlowLayout that will space things 5px apart FlowLayout f = new FlowLayout(FlowLayout.CENTER, 5, 0); // Make a small JPanel with the layout and make it non-opaque JPanel pnlTab = new JPanel(f); pnlTab.setOpaque(false); // Add a JLabel with title and the left-side tab icon JLabel lblTitle = new JLabel(title); // Create a JButton for the close tab button JButton btnClose = new JButton("x"); // btnClose.setOpaque(false); int size = 17; btnClose.setPreferredSize(new Dimension(size, size)); btnClose.setToolTipText("close this tab"); // Make the button looks the same for all Laf's btnClose.setUI(new BasicButtonUI()); // Make it transparent btnClose.setContentAreaFilled(false); // No need to be focusable btnClose.setFocusable(false); btnClose.setBorder(BorderFactory.createEtchedBorder()); btnClose.setBorderPainted(false); // Making nice rollover effect // we use the same listener for all buttons btnClose.setRolloverEnabled(true); // Close the proper tab by clicking the button // Configure icon and rollover icon for button btnClose.setRolloverEnabled(true); // Set border null so the button doesnt make the tab too big btnClose.setBorder(null); // Make sure the button cant get focus, otherwise it looks funny btnClose.setFocusable(false); // Put the panel together pnlTab.add(lblTitle); pnlTab.add(btnClose); // Add a thin border to keep the image below the top edge of the tab // when the tab is selected pnlTab.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); // Now assign the component for the tab tabbedPane.setTabComponentAt(pos, pnlTab); // Add the listener that removes the tab ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(new JFrame(), "Are you sure you want to remove this tab? All results will be lost!", "Remove tab", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { tabbedPane.remove(c); } } }; btnClose.addActionListener(listener); // Optionally bring the new tab to the front tabbedPane.setSelectedComponent(c); }
From source file:com.stefanbrenner.droplet.ui.DevicePanel.java
/** * Create the panel./*w w w .j a va 2s. c o m*/ */ public DevicePanel(final JComponent parent, final IDroplet droplet, final T device) { this.parent = parent; setDevice(device); setLayout(new BorderLayout(0, 5)); setBorder(BorderFactory.createLineBorder(Color.BLACK)); setBackground(DropletColors.getBackgroundColor(device)); BeanAdapter<T> adapter = new BeanAdapter<T>(device, true); // device name textfield txtName = BasicComponentFactory.createTextField(adapter.getValueModel(IDevice.PROPERTY_NAME)); txtName.setHorizontalAlignment(SwingConstants.CENTER); txtName.setColumns(1); txtName.setToolTipText(device.getName()); adapter.addBeanPropertyChangeListener(IDevice.PROPERTY_NAME, new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent event) { txtName.setToolTipText(device.getName()); } }); add(txtName, BorderLayout.NORTH); // actions panel with scroll pane actionsPanel = new JPanel(); actionsPanel.setLayout(new BoxLayout(actionsPanel, BoxLayout.Y_AXIS)); actionsPanel.setBackground(getBackground()); JScrollPane scrollPane = new JScrollPane(actionsPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); // resize vertical scrollbar scrollPane.getVerticalScrollBar().putClientProperty("JComponent.sizeVariant", "mini"); //$NON-NLS-1$ //$NON-NLS-2$ SwingUtilities.updateComponentTreeUI(scrollPane); // we need no border scrollPane.setBorder(BorderFactory.createEmptyBorder()); add(scrollPane, BorderLayout.CENTER); { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(0, 1)); createAddButton(panel); // remove button JButton btnRemove = new JButton(Messages.getString("ActionDevicePanel.removeDevice")); //$NON-NLS-1$ btnRemove.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent action) { int retVal = JOptionPane.showConfirmDialog(DevicePanel.this, Messages.getString("ActionDevicePanel.removeDevice") + " '" + device.getName() + "'?", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ StringUtils.EMPTY, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (retVal == JOptionPane.YES_OPTION) { droplet.removeDevice(device); } } }); btnRemove.setFocusable(false); panel.add(btnRemove); add(panel, BorderLayout.SOUTH); } }