JButton button = new JButton("Using Compound Border"); Border lineBorder = BorderFactory.createMatteBorder(2, 0, 0, 0, Color.BLACK); CompoundBorder border = new CompoundBorder(button.getBorder(), lineBorder); button.setBorder( border );
JButton myButton = new JButton("BUTTON TEXT"); myButton.setBorder(BorderFactory.createCompoundBorder(myButton.getBorder(), BorderFactory.createLineBorder(Color.RED));
@Override public void mouseEntered(MouseEvent e) { prevBorder = button.getBorder(); button.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER), BorderFactory.createEmptyBorder(3, 3, 3, 3))); button.setCursor(new Cursor(Cursor.HAND_CURSOR)); }
@Override public void mouseEntered(MouseEvent e) { this.prevBorder = button.getBorder(); CompoundBorder compoundBorder = BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(AppThemeColor.ADR_SELECTED_BORDER, 1), BorderFactory.createLineBorder(button.getBackground(), 3) ); button.setBorder(compoundBorder); button.setCursor(new Cursor(Cursor.HAND_CURSOR)); }
public ButtonColumn(JTable table, Action action, int column) { this.table = table; this.action = action; renderButton = new JButton(); editButton = new JButton(); editButton.setFocusPainted(false); editButton.addActionListener(this); originalBorder = editButton.getBorder(); enabled = true; TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(column).setCellRenderer(this); columnModel.getColumn(column).setCellEditor(this); table.addMouseListener(this); }
public ButtonsInCellRenderer(JTable table, JButton[] buttons, Action[] actions, int column) { this.table = table; this.actions = actions; this.buttons = buttons; for (JButton btn : buttons) { btn.setFocusPainted(false); btn.addActionListener(this); } border = buttons[0].getBorder(); setFocusBorder(new LineBorder(Color.BLUE)); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(column).setCellRenderer(this); columnModel.getColumn(column).setCellEditor(this); table.addMouseListener(this); panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.add(Box.createHorizontalGlue()); if (buttons.length > 0) panel.add(buttons[0]); for (int i = 1; i < buttons.length; i++) { panel.add(Box.createHorizontalStrut(BUTTON_SPACER)); panel.add(buttons[i]); } panel.add(Box.createHorizontalStrut(BUTTON_SPACER)); }
/** * Create the ButtonCellRenderer to be used as a renderer and editor. The * renderer and editor will automatically be installed on the TableColumn of * the specified column. * * @param table the table containing the button renderer/editor * @param action the Action to be invoked when the button is invoked * @param column the column to which the button renderer/editor is added */ public ButtonCellRenderer(JTable table, Action action, int column) { this.table = table; this.action = action; renderButton = new JButton(); editButton = new JButton(); editButton.setFocusPainted(false); editButton.addActionListener(this); originalBorder = editButton.getBorder(); setFocusBorder(new LineBorder(Color.BLUE)); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(column).setCellRenderer(this); columnModel.getColumn(column).setCellEditor(this); table.addMouseListener(this); }
/** * Create the ButtonColumn to be used as a renderer and editor. The * renderer and editor will automatically be installed on the TableColumn * of the specified column. * * @param table the table containing the button renderer/editor * @param action the Action to be invoked when the button is invoked * @param column the column to which the button renderer/editor is added * @since 0.2.3 */ public ButtonColumn(JTable table, Action action, int column) { this.table = table; this.action = action; renderButton = new JButton(); editButton = new JButton(); editButton.setFocusPainted(false); editButton.addActionListener(this); originalBorder = editButton.getBorder(); setFocusBorder(new LineBorder(Color.BLUE)); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(column).setCellRenderer(this); columnModel.getColumn(column).setCellEditor(this); table.addMouseListener(this); }
/** * Create the ButtonColumn to be used as a renderer and editor. The * renderer and editor will automatically be installed on the TableColumn * of the specified column. * * @param table the table containing the button renderer/editor * @param action the Action to be invoked when the button is invoked * @param column the column to which the button renderer/editor is added */ public ButtonColumn(JTable table, Action action, int column) { this.table = table; this.action = action; renderButton = new JButton(); editButton = new JButton(); editButton.setFocusPainted(false); editButton.addActionListener(this); originalBorder = editButton.getBorder(); setFocusBorder(new LineBorder(Color.BLUE)); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(column).setCellRenderer(this); columnModel.getColumn(column).setCellEditor(this); table.addMouseListener(this); }
/** * Create the ButtonColumn to be used as a renderer and editor. The renderer * and editor will automatically be installed on the TableColumn of the * specified column. * * @param table the table containing the button renderer/editor * @param action the Action to be invoked when the button is invoked * @param column the column to which the button renderer/editor is added */ public ButtonColumn(JTable table, Action action, int column) { this.table = table; this.action = action; renderButton = new JButton(); editButton = new JButton(); editButton.setFocusPainted(false); editButton.addActionListener(this); originalBorder = editButton.getBorder(); setFocusBorder(new LineBorder(Color.BLUE)); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(column).setCellRenderer(this); columnModel.getColumn(column).setCellEditor(this); table.addMouseListener(this); }
/** * Create the ButtonColumn to be used as a renderer and editor. The renderer * and editor will automatically be installed on the TableColumn of the * specified column. * * @param table * the table containing the button renderer/editor * @param action * the Action to be invoked when the button is invoked * @param column * the column to which the button renderer/editor is added */ public ButtonColumn(JTable table, Action action, int column) { this.table = table; this.action = action; renderButton = new JButton(); editButton = new JButton(); editButton.setFocusPainted(false); editButton.addActionListener(this); originalBorder = editButton.getBorder(); setFocusBorder(new LineBorder(Color.BLUE)); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(column).setCellRenderer(this); columnModel.getColumn(column).setCellEditor(this); table.addMouseListener(this); }
public static void equalizeButtonSizes(Graphics g, JButton... buttons) { String[] labels = BeanUtil.extractProperties(buttons, "text", String.class); // Get the largest width and height Dimension maxSize = new Dimension(0, 0); Rectangle2D textBounds = null; JButton button0 = buttons[0]; FontMetrics metrics = button0.getFontMetrics(button0.getFont()); for (int i = 0; i < labels.length; ++i) { textBounds = metrics.getStringBounds(labels[i], g); maxSize.width = Math.max(maxSize.width, (int) textBounds.getWidth()); maxSize.height = Math.max(maxSize.height, (int) textBounds.getHeight()); } Insets insets = button0.getBorder().getBorderInsets(button0); maxSize.width += insets.left + insets.right; maxSize.height += insets.top + insets.bottom; // reset preferred and maximum size since BoxLayout takes both into account for (JButton button : buttons) { button.setPreferredSize((Dimension) maxSize.clone()); button.setMaximumSize((Dimension) maxSize.clone()); } }
this.colorList.setCellRenderer(new ColorListCellRenderer() { private static final long serialVersionUID = 1L; private final Border defaultBorder = new JButton().getBorder(); @Override public Component getListCellRendererComponent(