JBPanelWithEmptyText (@NotNull JPanel buttonPanel, @NotNull JToggleButton button, @NotNull Color color) { JBPanelWithEmptyText panel = new JBPanelWithEmptyText() { @Override public Dimension getPreferredSize() { Dimension d = super.getSize(); d.width = d.height = Math.max(d.width, d.height); return d; } @Override public Dimension getMinimumSize() { return getPreferredSize(); } @Override public Dimension getMaximumSize() { return getPreferredSize(); } @Override public Color getBackground() { return button.isSelected() ? color : super.getBackground(); } @Override public boolean isOpaque() { return true; } }; //panel.putClientProperty(JComponent.TOOL_TIP_TEXT_KEY, button.getToolTipText()); panel.getEmptyText().clear(); new ClickListener() { @Override public boolean onClick(@NotNull MouseEvent event, int clickCount) { button.setSelected(button instanceof JRadioButton || !button.isSelected()); buttonPanel.invalidate(); buttonPanel.repaint(); return true; } }.installOn(panel); panel.setBorder(BorderFactory.createLineBorder(color)); buttonPanel.add(panel); return panel; }