JComponent () { DrawLabelMode drawLabelMode = shouldDrawLabel(); switch (drawLabelMode) { case ALWAYS -> myNameLabel = new DynamicLabel(() -> myDisplayName.get() + (isValueSelected() ? ": " : "")); case NEVER -> myNameLabel = null; case WHEN_VALUE_NOT_SET -> myNameLabel = new DynamicLabel(() -> isValueSelected() ? "" : myDisplayName.get()); default -> throw new IllegalStateException("Unexpected value: " + drawLabelMode); } myValueLabel = new DynamicLabel(this::getCurrentText); setDefaultForeground(); setFocusable(true); setBorder(wrapBorder(createUnfocusedBorder())); setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); myFilterActionButton = new InlineIconButton(AllIcons.Actions.Close); if (myNameLabel != null) add(myNameLabel); add(myValueLabel); add(Box.createHorizontalStrut(GAP_BEFORE_ARROW)); add(myFilterActionButton); myFilterActionButton.setActionListener(e -> { if (isValueSelected()) { resetFilter(); } else { showPopup(); } }); updateFilterButton(); installChangeListener(() -> { setDefaultForeground(); updateFilterButton(); myValueLabel.revalidate(); myValueLabel.repaint(); }); showPopupMenuOnClick(); showPopupMenuFromKeyboard(); if (shouldIndicateHovering()) { Stream.of(this, myFilterActionButton, myNameLabel, myValueLabel) .filter(nonNull()) .forEach(this::indicateHovering); } indicateFocusing(); setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); return this; }