mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-12 06:57:13 -06:00
ComboBox, Spinner and TextField: support round border style (set client property JComponent.roundRect to true)
This commit is contained in:
@@ -19,6 +19,7 @@ package com.formdev.flatlaf.testing;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.*;
|
||||
import com.formdev.flatlaf.FlatClientProperties;
|
||||
import net.miginfocom.swing.*;
|
||||
|
||||
/**
|
||||
@@ -63,6 +64,26 @@ public class FlatComponentsTest
|
||||
}
|
||||
}
|
||||
|
||||
private void roundRectChanged() {
|
||||
Boolean roundRect = roundRectCheckBox.isSelected() ? true : null;
|
||||
|
||||
for( Component c : getComponents() ) {
|
||||
if( c instanceof JComponent )
|
||||
((JComponent)c).putClientProperty( FlatClientProperties.COMPONENT_ROUND_RECT, roundRect );
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonTypeChanged() {
|
||||
String buttonType = (String) buttonTypeComboBox.getSelectedItem();
|
||||
if( "-".equals( buttonType ) )
|
||||
buttonType = null;
|
||||
|
||||
for( Component c : getComponents() ) {
|
||||
if( c instanceof AbstractButton )
|
||||
((AbstractButton)c).putClientProperty( FlatClientProperties.BUTTON_TYPE, buttonType );
|
||||
}
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
|
||||
JLabel labelLabel = new JLabel();
|
||||
@@ -104,12 +125,14 @@ public class FlatComponentsTest
|
||||
JCheckBox checkBox4 = new JCheckBox();
|
||||
JToggleButton toggleButton5 = new JToggleButton();
|
||||
JToggleButton toggleButton8 = new JToggleButton();
|
||||
buttonTypeComboBox = new JComboBox<>();
|
||||
JLabel radioButtonLabel = new JLabel();
|
||||
JRadioButton radioButton1 = new JRadioButton();
|
||||
JRadioButton radioButton2 = new JRadioButton();
|
||||
JRadioButton radioButton3 = new JRadioButton();
|
||||
JRadioButton radioButton4 = new JRadioButton();
|
||||
contentAreaFilledCheckBox = new JCheckBox();
|
||||
roundRectCheckBox = new JCheckBox();
|
||||
JLabel comboBoxLabel = new JLabel();
|
||||
JComboBox<String> comboBox1 = new JComboBox<>();
|
||||
JComboBox<String> comboBox2 = new JComboBox<>();
|
||||
@@ -481,6 +504,17 @@ public class FlatComponentsTest
|
||||
toggleButton8.setSelected(true);
|
||||
add(toggleButton8, "cell 5 3");
|
||||
|
||||
//---- buttonTypeComboBox ----
|
||||
buttonTypeComboBox.setModel(new DefaultComboBoxModel<>(new String[] {
|
||||
"-",
|
||||
"square",
|
||||
"roundRect",
|
||||
"tab",
|
||||
"help"
|
||||
}));
|
||||
buttonTypeComboBox.addActionListener(e -> buttonTypeChanged());
|
||||
add(buttonTypeComboBox, "cell 6 3");
|
||||
|
||||
//---- radioButtonLabel ----
|
||||
radioButtonLabel.setText("JRadioButton:");
|
||||
add(radioButtonLabel, "cell 0 4");
|
||||
@@ -513,6 +547,11 @@ public class FlatComponentsTest
|
||||
contentAreaFilledCheckBox.addActionListener(e -> contentAreaFilledChanged());
|
||||
add(contentAreaFilledCheckBox, "cell 5 4");
|
||||
|
||||
//---- roundRectCheckBox ----
|
||||
roundRectCheckBox.setText("roundRect");
|
||||
roundRectCheckBox.addActionListener(e -> roundRectChanged());
|
||||
add(roundRectCheckBox, "cell 6 4");
|
||||
|
||||
//---- comboBoxLabel ----
|
||||
comboBoxLabel.setText("JComboBox:");
|
||||
add(comboBoxLabel, "cell 0 5");
|
||||
@@ -1210,7 +1249,9 @@ public class FlatComponentsTest
|
||||
}
|
||||
|
||||
// JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
|
||||
private JComboBox<String> buttonTypeComboBox;
|
||||
private JCheckBox contentAreaFilledCheckBox;
|
||||
private JCheckBox roundRectCheckBox;
|
||||
private JProgressBar progressBar3;
|
||||
private JProgressBar progressBar4;
|
||||
private JSlider slider3;
|
||||
|
||||
@@ -296,6 +296,23 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 5 3"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JComboBox" ) {
|
||||
name: "buttonTypeComboBox"
|
||||
"model": new javax.swing.DefaultComboBoxModel {
|
||||
selectedItem: "-"
|
||||
addElement( "-" )
|
||||
addElement( "square" )
|
||||
addElement( "roundRect" )
|
||||
addElement( "tab" )
|
||||
addElement( "help" )
|
||||
}
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "buttonTypeChanged", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 6 3"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "radioButtonLabel"
|
||||
"text": "JRadioButton:"
|
||||
@@ -343,6 +360,16 @@ new FormModel {
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 5 4"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JCheckBox" ) {
|
||||
name: "roundRectCheckBox"
|
||||
"text": "roundRect"
|
||||
auxiliary() {
|
||||
"JavaCodeGenerator.variableLocal": false
|
||||
}
|
||||
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "roundRectChanged", false ) )
|
||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||
"value": "cell 6 4"
|
||||
} )
|
||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||
name: "comboBoxLabel"
|
||||
"text": "JComboBox:"
|
||||
|
||||
Reference in New Issue
Block a user