Skip to content

Commit

Permalink
ComboBox: do not paint arrow button background if it is hidden (issue #…
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCharly committed Dec 4, 2024
1 parent 1dcb251 commit e9a2184
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ public void update( Graphics g, JComponent c ) {
FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc );

// paint arrow button background
if( enabled && !isCellRenderer ) {
if( enabled && !isCellRenderer && arrowButton.isVisible() ) {
Color buttonColor = paintButton
? buttonEditableBackground
: (buttonFocusedBackground != null || focusedBackground != null) && isPermanentFocusOwner( comboBox )
Expand All @@ -612,7 +612,7 @@ public void update( Graphics g, JComponent c ) {
}

// paint vertical line between value and arrow button
if( paintButton ) {
if( paintButton && arrowButton.isVisible() ) {
Color separatorColor = enabled ? buttonSeparatorColor : buttonDisabledSeparatorColor;
if( separatorColor != null && buttonSeparatorWidth > 0 ) {
g2.setColor( separatorColor );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public static void main( String[] args ) {
};
for( JSlider slider : allSliders )
slider.addChangeListener( sliderChanged );

UIManager.addPropertyChangeListener( e -> {
if( "lookAndFeel".equals( e.getPropertyName() ) && hideArrowButtonCheckBox.isSelected() )
SwingUtilities.invokeLater( () -> hideArrowButton() );
} );
}

private void changeProgress() {
Expand Down Expand Up @@ -127,6 +132,18 @@ private void focusPaintedChanged() {
}
}

private void hideArrowButton() {
boolean hideArrowButton = hideArrowButtonCheckBox.isSelected();

for( Component c : getComponents() ) {
if( c instanceof JComboBox ) {
Component b = ((JComboBox<?>)c).getComponent( 0 );
if( b instanceof AbstractButton )
b.setVisible( !hideArrowButton );
}
}
}

private void roundRectChanged() {
Boolean roundRect = roundRectCheckBox.isSelected() ? true : null;

Expand Down Expand Up @@ -380,6 +397,7 @@ private void initComponents() {
magentaOutlineRadioButton = new JRadioButton();
magentaCyanOutlineRadioButton = new JRadioButton();
focusPaintedCheckBox = new JCheckBox();
hideArrowButtonCheckBox = new JCheckBox();
JLabel scrollBarLabel = new JLabel();
JScrollBar scrollBar1 = new JScrollBar();
JScrollBar scrollBar4 = new JScrollBar();
Expand Down Expand Up @@ -1234,9 +1252,10 @@ private void initComponents() {
"[]" +
"[]",
// rows
"[]" +
"[]" +
"[]" +
"[]0" +
"[]0" +
"[]0" +
"[]0" +
"[]"));

//---- buttonTypeComboBox ----
Expand Down Expand Up @@ -1290,13 +1309,18 @@ private void initComponents() {
magentaCyanOutlineRadioButton.addActionListener(e -> outlineChanged());
panel4.add(magentaCyanOutlineRadioButton);
}
panel5.add(panel4, "cell 0 2 1 2");
panel5.add(panel4, "cell 0 2 1 3");

//---- focusPaintedCheckBox ----
focusPaintedCheckBox.setText("focusPainted");
focusPaintedCheckBox.setSelected(true);
focusPaintedCheckBox.addActionListener(e -> focusPaintedChanged());
panel5.add(focusPaintedCheckBox, "cell 1 2");

//---- hideArrowButtonCheckBox ----
hideArrowButtonCheckBox.setText("hide arrow button");
hideArrowButtonCheckBox.addActionListener(e -> hideArrowButton());
panel5.add(hideArrowButtonCheckBox, "cell 1 3");
}
add(panel5, "cell 5 13 2 10,grow");

Expand Down Expand Up @@ -1703,6 +1727,7 @@ private void initComponents() {
private JRadioButton magentaOutlineRadioButton;
private JRadioButton magentaCyanOutlineRadioButton;
private JCheckBox focusPaintedCheckBox;
private JCheckBox hideArrowButtonCheckBox;
private JSlider slider1;
private JSlider slider6;
private JCheckBox sliderPaintTrackCheckBox;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
JFDML JFormDesigner: "7.0.5.0.404" Java: "17.0.2" encoding: "UTF-8"
JFDML JFormDesigner: "8.3" encoding: "UTF-8"

new FormModel {
contentType: "form/swing"
Expand Down Expand Up @@ -993,7 +993,7 @@ new FormModel {
} )
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$columnConstraints": "[][]"
"$rowConstraints": "[][][][]"
"$rowConstraints": "[]0[]0[]0[]0[]"
"$layoutConstraints": "ltr,insets dialog,hidemode 3"
} ) {
name: "panel5"
Expand Down Expand Up @@ -1092,7 +1092,7 @@ new FormModel {
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "outlineChanged", false ) )
} )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 2 1 2"
"value": "cell 0 2 1 3"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "focusPaintedCheckBox"
Expand All @@ -1105,6 +1105,16 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 2"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "hideArrowButtonCheckBox"
"text": "hide arrow button"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "hideArrowButton", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 1 3"
} )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 5 13 2 10,grow"
} )
Expand Down

0 comments on commit e9a2184

Please sign in to comment.