@Override public Component getListCellRendererComponent( JList<? extends E> list, E value, int index, boolean isSelected, boolean cellHasFocus) { label.setText(Objects.toString(value, "")); this.list = list; this.index = index; if (isSelected) { setBackground(list.getSelectionBackground()); label.setForeground(list.getSelectionForeground()); } else { setBackground(index % 2 == 0 ? EVEN_COLOR : list.getBackground()); label.setForeground(list.getForeground()); } MutableComboBoxModel m = (MutableComboBoxModel) list.getModel(); if (index < 0 || m.getSize() - 1 <= 0) { setOpaque(false); deleteButton.setVisible(false); label.setForeground(list.getForeground()); } else { boolean f = index == rolloverIndex; setOpaque(true); deleteButton.setVisible(true); deleteButton.getModel().setRollover(f); deleteButton.setForeground(f ? Color.WHITE : list.getForeground()); } return this; }
public ButtonsRenderer(RemoveButtonComboBox<E> comboBox) { super(new BorderLayout(0, 0)); this.comboBox = comboBox; label.setOpaque(false); setOpaque(true); add(label); deleteButton.setBorder(BorderFactory.createEmptyBorder()); deleteButton.setFocusable(false); deleteButton.setRolloverEnabled(false); deleteButton.setContentAreaFilled(false); add(deleteButton, BorderLayout.EAST); }
@Override public void mouseReleased(MouseEvent e) { JList list = (JList) e.getComponent(); Point pt = e.getPoint(); int index = list.locationToIndex(pt); if (index >= 0) { JButton button = getButton(list, pt, index); if (Objects.nonNull(button)) { button.doClick(); Rectangle r = list.getCellBounds(index, index); listRepaint(list, r); } } }
@Override protected JButton createArrowButton() { ImageIcon icon = new ImageIcon(getClass().getResource("14x14.png")); JButton button = new JButton(icon) { @Override public Dimension getPreferredSize() { return new Dimension(14, 14); } }; button.setRolloverIcon(makeRolloverIcon(icon)); button.setFocusPainted(false); button.setContentAreaFilled(false); return button; }
/** * Sets the <code>defaultButton</code> property, which determines the current default button for * this <code>JRootPane</code>. The default button is the button which will be activated when a * UI-defined activation event (typically the <b>Enter</b> key) occurs in the root pane regardless * of whether or not the button has keyboard focus (unless there is another component within the * root pane which consumes the activation event, such as a <code>JTextPane</code>). For default * activation to work, the button must be an enabled descendent of the root pane when activation * occurs. To remove a default button from this root pane, set this property to <code>null</code>. * * @see JButton#isDefaultButton * @param defaultButton the <code>JButton</code> which is to be the default button * @beaninfo description: The button activated by default in this root pane */ public void setDefaultButton(JButton defaultButton) { JButton oldDefault = this.defaultButton; if (oldDefault != defaultButton) { this.defaultButton = defaultButton; if (oldDefault != null) { oldDefault.repaint(); } if (defaultButton != null) { defaultButton.repaint(); } } firePropertyChange("defaultButton", oldDefault, defaultButton); }
public JButton createButton(Action a) { JButton b = new JButton() { public Dimension getMaximumSize() { int width = Short.MAX_VALUE; int height = super.getMaximumSize().height; return new Dimension(width, height); } }; // setting the following client property informs the button to show // the action text as it's name. The default is to not show the // action text. b.putClientProperty("displayActionText", Boolean.TRUE); b.setAction(a); // b.setAlignmentX(JButton.CENTER_ALIGNMENT); return b; }
public void actionPerformed(ActionEvent e) { if (owner != null && SwingUtilities.getRootPane(owner) == root) { ButtonModel model = owner.getModel(); if (press) { model.setArmed(true); model.setPressed(true); } else { model.setPressed(false); } } }
@Override public void mouseMoved(MouseEvent e) { JList list = (JList) e.getComponent(); Point pt = e.getPoint(); int index = list.locationToIndex(pt); if (!list.getCellBounds(index, index).contains(pt)) { if (prevIndex >= 0) { Rectangle r = list.getCellBounds(prevIndex, prevIndex); listRepaint(list, r); } index = -1; prevButton = null; return; } if (index >= 0) { JButton button = getButton(list, pt, index); ButtonsRenderer renderer = (ButtonsRenderer) list.getCellRenderer(); if (Objects.nonNull(button)) { renderer.rolloverIndex = index; if (!button.equals(prevButton)) { Rectangle r = list.getCellBounds(prevIndex, index); listRepaint(list, r); } } else { renderer.rolloverIndex = -1; Rectangle r = null; if (prevIndex == index) { if (prevIndex >= 0 && Objects.nonNull(prevButton)) { r = list.getCellBounds(prevIndex, prevIndex); } } else { r = list.getCellBounds(index, index); } listRepaint(list, r); prevIndex = -1; } prevButton = button; } prevIndex = index; }
private void initialise() { setSize(180, 120); setLocation(300, 200); setTitle("Working..."); setVisible(false); setModal(true); setResizable(false); setDefaultCloseOperation(0); _stopped = false; getContentPane().setLayout(new BorderLayout()); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); busyTextLabel = new JLabel("Busy - please wait"); topPanel.add(busyTextLabel, "Center"); busyIcon = FTAUtilities.loadImageIcon("busy.gif"); busyIconLabel = new JLabel(busyIcon); topPanel.add(busyIconLabel, "West"); progressBar = new JProgressBar(); topPanel.add(progressBar, "South"); getContentPane().add(topPanel); stopButton = new JButton("Stop"); stopButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // System.out.println("'Stop' button pressed"); _stopped = true; } }); this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { _stopped = true; } }); // create panel to hold buttons JPanel buttonPanel = new JPanel(new FlowLayout()); buttonPanel.add(stopButton); getContentPane().add(buttonPanel, BorderLayout.SOUTH); }
public JButton createImageButton(Action a) { JButton b = new JButton(a); b.setMargin(new Insets(0, 0, 0, 0)); return b; }
public boolean isEnabled() { return owner.getModel().isEnabled(); }