Skip to content

Commit 52f686b

Browse files
committed
JideTabbedPane:
- repaint if client property `JTabbedPane.tabType` changed - some minor code "synization" with `FlatTabbedPaneUI`
1 parent 34c67a0 commit 52f686b

4 files changed

Lines changed: 82 additions & 35 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ FlatLaf Change Log
1414
(issue #1103)
1515
- TextComponents: Fixed preferred width when leading/trailing components or
1616
icons are present. (issue #1110)
17+
- JideTabbedPane: Support card tabs. (PR #1094)
1718

1819

1920
## 3.7.1

flatlaf-jide-oss/src/main/java/com/formdev/flatlaf/jideoss/ui/FlatJideTabbedPaneUI.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static com.formdev.flatlaf.FlatClientProperties.COMPONENT_TITLE_BAR_CAPTION;
2020
import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_HAS_FULL_BORDER;
2121
import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_SHOW_TAB_SEPARATORS;
22+
import static com.formdev.flatlaf.FlatClientProperties.TABBED_PANE_TAB_TYPE;
2223
import static com.formdev.flatlaf.FlatClientProperties.clientPropertyBoolean;
2324
import static com.formdev.flatlaf.util.UIScale.scale;
2425
import java.awt.Color;
@@ -239,6 +240,10 @@ protected PropertyChangeListener createPropertyChangeListener() {
239240
_tabPane.revalidate();
240241
_tabPane.repaint();
241242
break;
243+
244+
case TABBED_PANE_TAB_TYPE:
245+
_tabPane.repaint();
246+
break;
242247
}
243248
};
244249
}
@@ -432,19 +437,23 @@ protected void paintTabBorder( Graphics g, int tabPlacement, int tabIndex, int x
432437
{
433438
// paint tab separators
434439
if( clientPropertyBoolean( _tabPane, TABBED_PANE_SHOW_TAB_SEPARATORS, showTabSeparators ) &&
435-
!isLastInRun( tabIndex ) ) {
436-
if( !isCardTabType() || !isSelected ) {
440+
!isLastInRun( tabIndex ) )
441+
{
442+
if( isCardTabType() ) {
443+
// some separators need to be omitted if selected tab is painted as card
437444
int selectedIndex = _tabPane.getSelectedIndex();
438-
if( !isCardTabType() || (tabIndex != selectedIndex - 1 && tabIndex != selectedIndex) )
445+
if( tabIndex != selectedIndex - 1 && tabIndex != selectedIndex )
439446
paintTabSeparator( g, tabPlacement, x, y, w, h );
440-
}
447+
} else
448+
paintTabSeparator( g, tabPlacement, x, y, w, h );
441449
}
442450

443-
if( isSelected ) {
444-
if( isCardTabType() )
445-
paintCardTabBorder( g, tabPlacement, x, y, w, h );
451+
// paint active tab border
452+
if( isSelected && isCardTabType() )
453+
paintCardTabBorder( g, tabPlacement, x, y, w, h );
454+
455+
if( isSelected )
446456
paintTabSelection( g, tabPlacement, x, y, w, h );
447-
}
448457
}
449458

450459
protected void paintTabSeparator( Graphics g, int tabPlacement, int x, int y, int w, int h ) {
@@ -699,7 +708,7 @@ private static int parseTabType( String str ) {
699708
}
700709

701710
private int getTabType() {
702-
Object value = _tabPane.getClientProperty( "JTabbedPane.tabType" );
711+
Object value = _tabPane.getClientProperty( TABBED_PANE_TAB_TYPE );
703712
if( value instanceof String )
704713
return parseTabType( (String) value );
705714
return tabType;

flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssContainerTest.java

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import javax.swing.border.*;
2323
import com.formdev.flatlaf.FlatClientProperties;
2424
import com.formdev.flatlaf.FlatLaf;
25+
import com.formdev.flatlaf.extras.components.FlatTabbedPane.TabType;
2526
import com.formdev.flatlaf.icons.FlatInternalFrameCloseIcon;
2627
import com.formdev.flatlaf.testing.*;
2728
import com.formdev.flatlaf.testing.FlatTestFrame;
@@ -47,6 +48,8 @@ public static void main( String[] args ) {
4748
FlatJideOssContainerTest() {
4849
initComponents();
4950

51+
tabTypeComboBox.init( TabType.class, true );
52+
5053
tabPlacementField.init( TabPlacement.class, true );
5154
tabAlignmentField.init( JideTabAlignment.class, false );
5255
tabResizeModeField.init( JideTabResizeMode.class, true );
@@ -281,6 +284,12 @@ private void tabResizeModeChanged() {
281284
tabbedPane.setTabResizeMode( resizeMode );
282285
}
283286

287+
private void tabTypeChanged() {
288+
TabType value = tabTypeComboBox.getSelectedValue();
289+
for( JideTabbedPane tabbedPane : allTabbedPanes )
290+
tabbedPane.putClientProperty( FlatClientProperties.TABBED_PANE_TAB_TYPE, (value != null) ? value.toString() : null );
291+
}
292+
284293
private void tabBackForegroundChanged() {
285294
for( JTabbedPane tabbedPane : allTabbedPanes )
286295
tabBackForegroundChanged( tabbedPane );
@@ -434,6 +443,8 @@ private void initComponents() {
434443
tabAlignmentField = new FlatTestEnumSelector<>();
435444
JLabel tabResizeModeLabel = new JLabel();
436445
tabResizeModeField = new FlatTestEnumSelector<>();
446+
JLabel tabTypeLabel = new JLabel();
447+
tabTypeComboBox = new FlatTestEnumSelector<>();
437448
leadingComponentCheckBox = new JCheckBox();
438449
customBorderCheckBox = new JCheckBox();
439450
tabAreaInsetsCheckBox = new JCheckBox();
@@ -501,6 +512,7 @@ private void initComponents() {
501512
"[]" +
502513
"[]" +
503514
"[]" +
515+
"[]" +
504516
"[]para" +
505517
"[]" +
506518
"[]para" +
@@ -605,65 +617,73 @@ private void initComponents() {
605617
tabResizeModeField.addActionListener(e -> tabResizeModeChanged());
606618
tabbedPaneControlPanel.add(tabResizeModeField, "cell 2 5");
607619

620+
//---- tabTypeLabel ----
621+
tabTypeLabel.setText("Tab type:");
622+
tabbedPaneControlPanel.add(tabTypeLabel, "cell 0 6");
623+
624+
//---- tabTypeComboBox ----
625+
tabTypeComboBox.addActionListener(e -> tabTypeChanged());
626+
tabbedPaneControlPanel.add(tabTypeComboBox, "cell 1 6");
627+
608628
//---- leadingComponentCheckBox ----
609629
leadingComponentCheckBox.setText("Leading component");
610630
leadingComponentCheckBox.addActionListener(e -> leadingComponentChanged());
611-
tabbedPaneControlPanel.add(leadingComponentCheckBox, "cell 0 6");
631+
tabbedPaneControlPanel.add(leadingComponentCheckBox, "cell 0 7");
612632

613633
//---- customBorderCheckBox ----
614634
customBorderCheckBox.setText("Custom border");
615635
customBorderCheckBox.addActionListener(e -> customBorderChanged());
616-
tabbedPaneControlPanel.add(customBorderCheckBox, "cell 1 6");
636+
tabbedPaneControlPanel.add(customBorderCheckBox, "cell 1 7");
617637

618638
//---- tabAreaInsetsCheckBox ----
619639
tabAreaInsetsCheckBox.setText("Tab area insets (5,5,10,10)");
620640
tabAreaInsetsCheckBox.addActionListener(e -> tabAreaInsetsChanged());
621-
tabbedPaneControlPanel.add(tabAreaInsetsCheckBox, "cell 2 6");
641+
tabbedPaneControlPanel.add(tabAreaInsetsCheckBox, "cell 2 7");
622642

623643
//---- trailingComponentCheckBox ----
624644
trailingComponentCheckBox.setText("Trailing component");
625645
trailingComponentCheckBox.addActionListener(e -> trailingComponentChanged());
626-
tabbedPaneControlPanel.add(trailingComponentCheckBox, "cell 0 7");
646+
tabbedPaneControlPanel.add(trailingComponentCheckBox, "cell 0 8");
627647

628648
//---- hasFullBorderCheckBox ----
629649
hasFullBorderCheckBox.setText("Show content border");
630650
hasFullBorderCheckBox.addActionListener(e -> hasFullBorderChanged());
631-
tabbedPaneControlPanel.add(hasFullBorderCheckBox, "cell 1 7,alignx left,growx 0");
651+
tabbedPaneControlPanel.add(hasFullBorderCheckBox, "cell 1 8,alignx left,growx 0");
632652

633653
//---- boldActiveTabCheckBox ----
634654
boldActiveTabCheckBox.setText("Bold active tab");
635655
boldActiveTabCheckBox.addActionListener(e -> boldActiveTabChanged());
636-
tabbedPaneControlPanel.add(boldActiveTabCheckBox, "cell 0 8");
656+
tabbedPaneControlPanel.add(boldActiveTabCheckBox, "cell 0 9");
637657

638658
//---- showTabButtonsCheckBox ----
639659
showTabButtonsCheckBox.setText("Show tab buttons always");
640660
showTabButtonsCheckBox.addActionListener(e -> showTabButtonsChanged());
641-
tabbedPaneControlPanel.add(showTabButtonsCheckBox, "cell 1 8");
661+
tabbedPaneControlPanel.add(showTabButtonsCheckBox, "cell 1 9");
642662

643663
//---- smallerInsetsCheckBox ----
644664
smallerInsetsCheckBox.setText("Smaller tab insets (2,2,2,2)");
645665
smallerInsetsCheckBox.addActionListener(e -> smallerInsetsChanged());
646-
tabbedPaneControlPanel.add(smallerInsetsCheckBox, "cell 2 8");
666+
tabbedPaneControlPanel.add(smallerInsetsCheckBox, "cell 2 9");
647667

648668
//---- showGripperCheckBox ----
649669
showGripperCheckBox.setText("Show gripper");
650670
showGripperCheckBox.addActionListener(e -> showGripperChanged());
651-
tabbedPaneControlPanel.add(showGripperCheckBox, "cell 0 9");
671+
tabbedPaneControlPanel.add(showGripperCheckBox, "cell 0 10");
652672

653673
//---- showTabSeparatorsCheckBox ----
654674
showTabSeparatorsCheckBox.setText("Show tab separators");
655675
showTabSeparatorsCheckBox.addActionListener(e -> showTabSeparatorsChanged());
656-
tabbedPaneControlPanel.add(showTabSeparatorsCheckBox, "cell 1 9");
676+
tabbedPaneControlPanel.add(showTabSeparatorsCheckBox, "cell 1 10");
657677

658678
//---- tabEditingAllowedCheckBox ----
659679
tabEditingAllowedCheckBox.setText("Tab editing allowed");
660680
tabEditingAllowedCheckBox.addActionListener(e -> tabEditingAllowedChanged());
661-
tabbedPaneControlPanel.add(tabEditingAllowedCheckBox, "cell 0 10");
681+
tabbedPaneControlPanel.add(tabEditingAllowedCheckBox, "cell 0 11");
662682

663683
//---- hideTabAreaWithOneTabCheckBox ----
664684
hideTabAreaWithOneTabCheckBox.setText("Hide tab area with one tab");
665685
hideTabAreaWithOneTabCheckBox.addActionListener(e -> hideTabAreaWithOneTabChanged());
666-
tabbedPaneControlPanel.add(hideTabAreaWithOneTabCheckBox, "cell 1 10");
686+
tabbedPaneControlPanel.add(hideTabAreaWithOneTabCheckBox, "cell 1 11");
667687
}
668688
panel9.add(tabbedPaneControlPanel, cc.xywh(1, 7, 3, 1));
669689
}
@@ -694,6 +714,7 @@ private void initComponents() {
694714
private JCheckBox showCloseButtonOnMouseOverCheckBox;
695715
private FlatTestEnumSelector<JideTabAlignment> tabAlignmentField;
696716
private FlatTestEnumSelector<JideTabResizeMode> tabResizeModeField;
717+
private FlatTestEnumSelector<TabType> tabTypeComboBox;
697718
private JCheckBox leadingComponentCheckBox;
698719
private JCheckBox customBorderCheckBox;
699720
private JCheckBox tabAreaInsetsCheckBox;

flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/jideoss/FlatJideOssContainerTest.jfd

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
JFDML JFormDesigner: "8.2.0.0.331" Java: "21" encoding: "UTF-8"
1+
JFDML JFormDesigner: "8.3" encoding: "UTF-8"
22

33
new FormModel {
44
contentType: "form/swing"
@@ -65,7 +65,7 @@ new FormModel {
6565
add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestFrame$NoRightToLeftPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) {
6666
"$layoutConstraints": "insets 0,hidemode 3"
6767
"$columnConstraints": "[][][]"
68-
"$rowConstraints": "[center][][][][][]para[][]para[][][]"
68+
"$rowConstraints": "[center][][][][][][]para[][]para[][][]"
6969
} ) {
7070
name: "tabbedPaneControlPanel"
7171
"opaque": false
@@ -268,6 +268,22 @@ new FormModel {
268268
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
269269
"value": "cell 2 5"
270270
} )
271+
add( new FormComponent( "javax.swing.JLabel" ) {
272+
name: "tabTypeLabel"
273+
"text": "Tab type:"
274+
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
275+
"value": "cell 0 6"
276+
} )
277+
add( new FormComponent( "com.formdev.flatlaf.testing.FlatTestEnumSelector" ) {
278+
name: "tabTypeComboBox"
279+
auxiliary() {
280+
"JavaCodeGenerator.typeParameters": "TabType"
281+
"JavaCodeGenerator.variableLocal": false
282+
}
283+
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tabTypeChanged", false ) )
284+
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
285+
"value": "cell 1 6"
286+
} )
271287
add( new FormComponent( "javax.swing.JCheckBox" ) {
272288
name: "leadingComponentCheckBox"
273289
"text": "Leading component"
@@ -276,7 +292,7 @@ new FormModel {
276292
}
277293
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "leadingComponentChanged", false ) )
278294
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
279-
"value": "cell 0 6"
295+
"value": "cell 0 7"
280296
} )
281297
add( new FormComponent( "javax.swing.JCheckBox" ) {
282298
name: "customBorderCheckBox"
@@ -286,7 +302,7 @@ new FormModel {
286302
}
287303
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "customBorderChanged", false ) )
288304
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
289-
"value": "cell 1 6"
305+
"value": "cell 1 7"
290306
} )
291307
add( new FormComponent( "javax.swing.JCheckBox" ) {
292308
name: "tabAreaInsetsCheckBox"
@@ -296,7 +312,7 @@ new FormModel {
296312
}
297313
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tabAreaInsetsChanged", false ) )
298314
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
299-
"value": "cell 2 6"
315+
"value": "cell 2 7"
300316
} )
301317
add( new FormComponent( "javax.swing.JCheckBox" ) {
302318
name: "trailingComponentCheckBox"
@@ -306,7 +322,7 @@ new FormModel {
306322
}
307323
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "trailingComponentChanged", false ) )
308324
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
309-
"value": "cell 0 7"
325+
"value": "cell 0 8"
310326
} )
311327
add( new FormComponent( "javax.swing.JCheckBox" ) {
312328
name: "hasFullBorderCheckBox"
@@ -316,7 +332,7 @@ new FormModel {
316332
}
317333
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "hasFullBorderChanged", false ) )
318334
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
319-
"value": "cell 1 7,alignx left,growx 0"
335+
"value": "cell 1 8,alignx left,growx 0"
320336
} )
321337
add( new FormComponent( "javax.swing.JCheckBox" ) {
322338
name: "boldActiveTabCheckBox"
@@ -326,7 +342,7 @@ new FormModel {
326342
}
327343
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "boldActiveTabChanged", false ) )
328344
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
329-
"value": "cell 0 8"
345+
"value": "cell 0 9"
330346
} )
331347
add( new FormComponent( "javax.swing.JCheckBox" ) {
332348
name: "showTabButtonsCheckBox"
@@ -336,7 +352,7 @@ new FormModel {
336352
}
337353
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showTabButtonsChanged", false ) )
338354
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
339-
"value": "cell 1 8"
355+
"value": "cell 1 9"
340356
} )
341357
add( new FormComponent( "javax.swing.JCheckBox" ) {
342358
name: "smallerInsetsCheckBox"
@@ -346,7 +362,7 @@ new FormModel {
346362
}
347363
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "smallerInsetsChanged", false ) )
348364
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
349-
"value": "cell 2 8"
365+
"value": "cell 2 9"
350366
} )
351367
add( new FormComponent( "javax.swing.JCheckBox" ) {
352368
name: "showGripperCheckBox"
@@ -356,7 +372,7 @@ new FormModel {
356372
}
357373
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showGripperChanged", false ) )
358374
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
359-
"value": "cell 0 9"
375+
"value": "cell 0 10"
360376
} )
361377
add( new FormComponent( "javax.swing.JCheckBox" ) {
362378
name: "showTabSeparatorsCheckBox"
@@ -366,7 +382,7 @@ new FormModel {
366382
}
367383
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "showTabSeparatorsChanged", false ) )
368384
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
369-
"value": "cell 1 9"
385+
"value": "cell 1 10"
370386
} )
371387
add( new FormComponent( "javax.swing.JCheckBox" ) {
372388
name: "tabEditingAllowedCheckBox"
@@ -376,7 +392,7 @@ new FormModel {
376392
}
377393
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "tabEditingAllowedChanged", false ) )
378394
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
379-
"value": "cell 0 10"
395+
"value": "cell 0 11"
380396
} )
381397
add( new FormComponent( "javax.swing.JCheckBox" ) {
382398
name: "hideTabAreaWithOneTabCheckBox"
@@ -386,7 +402,7 @@ new FormModel {
386402
}
387403
addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "hideTabAreaWithOneTabChanged", false ) )
388404
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
389-
"value": "cell 1 10"
405+
"value": "cell 1 11"
390406
} )
391407
}, new FormLayoutConstraints( class com.jgoodies.forms.layout.CellConstraints ) {
392408
"gridY": 7

0 commit comments

Comments
 (0)