TabbedPane: fixed IndexOutOfBoundsException when using tooltip text on close buttons and closing last/rightmost tab (issue #235)

This commit is contained in:
Karl Tauber
2021-01-10 18:28:30 +01:00
parent 7d48bf06fe
commit 14222e40ad
3 changed files with 17 additions and 6 deletions

View File

@@ -21,6 +21,8 @@ FlatLaf Change Log
- Button and ToggleButton: Threat Unicode surrogate character pair as single
character and make button square. (issue #234)
- TabbedPane: Fixed `IndexOutOfBoundsException` when using tooltip text on close
buttons and closing last/rightmost tab. (issue #235)
- Extras: Added missing export of package
`com.formdev.flatlaf.extras.components` to Java 9 module descriptor.
- JIDE Common Layer: Invoke `LookAndFeelFactory.installJideExtension()` when

View File

@@ -2109,8 +2109,10 @@ public class FlatTabbedPaneUI
public void mouseReleased( MouseEvent e ) {
if( isPressedTabClose() ) {
updateRollover( e );
if( pressedTabIndex >= 0 && pressedTabIndex == getRolloverTab() )
if( pressedTabIndex >= 0 && pressedTabIndex == getRolloverTab() ) {
restoreTabToolTip();
closeTab( pressedTabIndex );
}
} else
mouseDelegate.mouseReleased( e );
@@ -2188,7 +2190,8 @@ public class FlatTabbedPaneUI
if( lastTipTabIndex < 0 )
return;
tabPane.setToolTipTextAt( lastTipTabIndex, lastTip );
if( lastTipTabIndex < tabPane.getTabCount() )
tabPane.setToolTipTextAt( lastTipTabIndex, lastTip );
lastTip = null;
lastTipTabIndex = -1;
}

View File

@@ -105,11 +105,11 @@ public class FlatContainerTest
}
private void tabCountChanged() {
for( JTabbedPane tabbedPane : allTabbedPanes )
for( FlatTabbedPane tabbedPane : allTabbedPanes )
tabCountChanged( tabbedPane );
}
private void tabCountChanged( JTabbedPane tabbedPane ) {
private void tabCountChanged( FlatTabbedPane tabbedPane ) {
int oldTabCount = tabbedPane.getTabCount();
int newTabCount = (Integer) tabCountSpinner.getValue();
@@ -126,7 +126,7 @@ public class FlatContainerTest
setTabIcons( tabbedPane );
}
private void addTab( JTabbedPane tabbedPane ) {
private void addTab( FlatTabbedPane tabbedPane ) {
switch( tabbedPane.getTabCount() ) {
case 0:
tabbedPane.addTab( "Tab 1", null, new Panel1(), "First tab." );
@@ -136,12 +136,14 @@ public class FlatContainerTest
JComponent tab2 = new Panel2();
tab2.setBorder( new LineBorder( Color.magenta ) );
tabbedPane.addTab( "Second Tab", null, tab2, "This is the second tab." );
tabbedPane.setTabCloseToolTipText( 1, "Close Second Tab" );
break;
case 2:
tabbedPane.addTab( "Disabled", createTab( "tab content 3" ) );
tabbedPane.setEnabledAt( 2, false );
tabbedPane.setToolTipTextAt( 2, "Disabled tab." );
tabbedPane.setTabCloseToolTipText( 2, "Close Disabled tab" );
break;
case 3:
@@ -348,9 +350,13 @@ public class FlatContainerTest
if( closable ) {
for( FlatTabbedPane tabbedPane : allTabbedPanes ) {
tabbedPane.setTabCloseCallback( (tabbedPane2, tabIndex) -> {
String tabTitle = tabbedPane2.getTitleAt( tabIndex );
AWTEvent e = EventQueue.getCurrentEvent();
int modifiers = (e instanceof MouseEvent) ? ((MouseEvent)e).getModifiers() : 0;
JOptionPane.showMessageDialog( this, "Closed tab '" + tabbedPane2.getTitleAt( tabIndex ) + "'."
tabbedPane2.removeTabAt( tabIndex );
JOptionPane.showMessageDialog( this, "Closed tab '" + tabTitle + "'."
+ "\n\n(modifiers: " + MouseEvent.getMouseModifiersText( modifiers ) + ")",
"Tab Closed", JOptionPane.PLAIN_MESSAGE );
} );