mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
TabbedPane: fixed IndexOutOfBoundsException when using tooltip text on close buttons and closing last/rightmost tab (issue #235)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
} );
|
||||
|
||||
Reference in New Issue
Block a user