TabbedPane: support specifying tab insets via client property

This commit is contained in:
Karl Tauber
2020-10-21 01:14:26 +02:00
parent 9bc656a5c5
commit 6d38e44f91
4 changed files with 119 additions and 19 deletions

View File

@@ -299,6 +299,26 @@ public class FlatContainerTest
}
}
private void smallerTabHeightChanged() {
Integer tabHeight = smallerTabHeightCheckBox.isSelected() ? 20 : null;
putTabbedPanesClientProperty( TABBED_PANE_TAB_HEIGHT, tabHeight );
}
private void smallerInsetsChanged() {
Insets insets = smallerInsetsCheckBox.isSelected() ? new Insets( 2, 2, 2, 2 ) : null;
putTabbedPanesClientProperty( TABBED_PANE_TAB_INSETS, insets );
}
private void secondTabWiderChanged() {
Insets insets = secondTabWiderCheckBox.isSelected() ? new Insets( 4, 20, 4, 20 ) : null;
JTabbedPane[] tabbedPanes = new JTabbedPane[] { tabbedPane1, tabbedPane2, tabbedPane3, tabbedPane4 };
for( JTabbedPane tabbedPane : tabbedPanes ) {
Component c = tabbedPane.getComponentAt( 1 );
((JComponent)c).putClientProperty( TABBED_PANE_TAB_INSETS, insets );
}
}
private void initComponents() {
// JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
JPanel panel9 = new JPanel();
@@ -337,6 +357,9 @@ public class FlatContainerTest
trailingComponentCheckBox = new JCheckBox();
tabsClosableCheckBox = new JCheckBox();
secondTabClosableCheckBox = new TriStateCheckBox();
smallerTabHeightCheckBox = new JCheckBox();
smallerInsetsCheckBox = new JCheckBox();
secondTabWiderCheckBox = new JCheckBox();
CellConstraints cc = new CellConstraints();
//======== this ========
@@ -451,6 +474,7 @@ public class FlatContainerTest
"[center]" +
"[]" +
"[]" +
"[]" +
"[]"));
//---- moreTabsCheckBox ----
@@ -559,6 +583,21 @@ public class FlatContainerTest
secondTabClosableCheckBox.setText("Second Tab closable");
secondTabClosableCheckBox.addActionListener(e -> secondTabClosableChanged());
panel14.add(secondTabClosableCheckBox, "cell 3 3");
//---- smallerTabHeightCheckBox ----
smallerTabHeightCheckBox.setText("Smaller tab height");
smallerTabHeightCheckBox.addActionListener(e -> smallerTabHeightChanged());
panel14.add(smallerTabHeightCheckBox, "cell 0 4 2 1");
//---- smallerInsetsCheckBox ----
smallerInsetsCheckBox.setText("Smaller insets");
smallerInsetsCheckBox.addActionListener(e -> smallerInsetsChanged());
panel14.add(smallerInsetsCheckBox, "cell 2 4");
//---- secondTabWiderCheckBox ----
secondTabWiderCheckBox.setText("Second Tab wider");
secondTabWiderCheckBox.addActionListener(e -> secondTabWiderChanged());
panel14.add(secondTabWiderCheckBox, "cell 3 4");
}
panel9.add(panel14, cc.xywh(1, 11, 3, 1));
}
@@ -588,6 +627,9 @@ public class FlatContainerTest
private JCheckBox trailingComponentCheckBox;
private JCheckBox tabsClosableCheckBox;
private TriStateCheckBox secondTabClosableCheckBox;
private JCheckBox smallerTabHeightCheckBox;
private JCheckBox smallerInsetsCheckBox;
private JCheckBox secondTabWiderCheckBox;
// JFormDesigner - End of variables declaration //GEN-END:variables
//---- class Tab1Panel ----------------------------------------------------

View File

@@ -132,7 +132,7 @@ new FormModel {
add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
"$layoutConstraints": "insets 0,hidemode 3"
"$columnConstraints": "[][fill][][][fill]"
"$rowConstraints": "[center][][][]"
"$rowConstraints": "[center][][][][]"
} ) {
name: "panel14"
"opaque": false
@@ -347,6 +347,36 @@ new FormModel {
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 3"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "smallerTabHeightCheckBox"
"text": "Smaller tab height"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "smallerTabHeightChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 0 4 2 1"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "smallerInsetsCheckBox"
"text": "Smaller insets"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "smallerInsetsChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 2 4"
} )
add( new FormComponent( "javax.swing.JCheckBox" ) {
name: "secondTabWiderCheckBox"
"text": "Second Tab wider"
auxiliary() {
"JavaCodeGenerator.variableLocal": false
}
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "secondTabWiderChanged", false ) )
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
"value": "cell 3 4"
} )
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
"gridY": 11
"gridWidth": 3