public CustomizableComboBox() { super(new BorderLayout()); myThemedCombo.setEditable(true); PopupMouseListener listener = new PopupMouseListener(); // GTK always draws a border on the textbox. It cannot be removed, // so to compensate, we remove our own border so we don't have a double border. if (UIUtil.isUnderGTKLookAndFeel()) { this.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); } else { this.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(2, 2, 2, 2), BorderFactory.createLineBorder(getBorderColor(), 1))); } // Try to turn off the border on the JTextField. myTextField = new JBTextField() { @Override public void setBorder(Border border) { super.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0)); } }; myTextField.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0)); myTextField.addMouseListener(listener); myTextField.addFocusListener( new FocusListener() { @Override public void focusGained(FocusEvent e) { myTextField.selectAll(); } @Override public void focusLost(FocusEvent e) { // no-op } }); JButton popupButton = createArrowButton(); popupButton.addMouseListener(listener); this.add(popupButton, BorderLayout.EAST); this.add(myTextField, BorderLayout.CENTER); }
@Override public void addNotify() { super.addNotify(); myTextField.addFocusListener( new FocusAdapter() { @Override public void focusGained(FocusEvent e) { CustomizableComboBox.this.repaint(); } @Override public void focusLost(FocusEvent e) { CustomizableComboBox.this.repaint(); } }); }