mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 22:47:13 -06:00
TabbedPane: search for label or text component in custom tab component and use its text in "more tabs" popup (issue #207; PR #190)
This commit is contained in:
@@ -60,6 +60,7 @@ import javax.swing.ButtonModel;
|
|||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
@@ -76,6 +77,7 @@ import javax.swing.event.PopupMenuListener;
|
|||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
import javax.swing.plaf.basic.BasicTabbedPaneUI;
|
import javax.swing.plaf.basic.BasicTabbedPaneUI;
|
||||||
|
import javax.swing.text.JTextComponent;
|
||||||
import javax.swing.text.View;
|
import javax.swing.text.View;
|
||||||
import com.formdev.flatlaf.FlatLaf;
|
import com.formdev.flatlaf.FlatLaf;
|
||||||
import com.formdev.flatlaf.util.Animator;
|
import com.formdev.flatlaf.util.Animator;
|
||||||
@@ -1549,7 +1551,11 @@ public class FlatTabbedPaneUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected JMenuItem createMenuItem( int index ) {
|
protected JMenuItem createMenuItem( int index ) {
|
||||||
JMenuItem menuItem = new JMenuItem( tabPane.getTitleAt( index ), tabPane.getIconAt( index ) );
|
String title = tabPane.getTitleAt( index );
|
||||||
|
if( title == null || title.isEmpty() )
|
||||||
|
title = findTabTitle( tabPane.getTabComponentAt( index ) );
|
||||||
|
|
||||||
|
JMenuItem menuItem = new JMenuItem( title, tabPane.getIconAt( index ) );
|
||||||
menuItem.setDisabledIcon( tabPane.getDisabledIconAt( index ) );
|
menuItem.setDisabledIcon( tabPane.getDisabledIconAt( index ) );
|
||||||
menuItem.setToolTipText( tabPane.getToolTipTextAt( index ) );
|
menuItem.setToolTipText( tabPane.getToolTipTextAt( index ) );
|
||||||
|
|
||||||
@@ -1570,6 +1576,33 @@ public class FlatTabbedPaneUI
|
|||||||
return menuItem;
|
return menuItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search for label or text component in custom tab component and return its text.
|
||||||
|
*/
|
||||||
|
private String findTabTitle( Component c ) {
|
||||||
|
if( c == null )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
String title = null;
|
||||||
|
if( c instanceof JLabel )
|
||||||
|
title = ((JLabel)c).getText();
|
||||||
|
else if( c instanceof JTextComponent )
|
||||||
|
title = ((JTextComponent)c).getText();
|
||||||
|
|
||||||
|
if( title != null && !title.isEmpty() )
|
||||||
|
return title;
|
||||||
|
|
||||||
|
if( c instanceof Container ) {
|
||||||
|
for( Component child : ((Container)c).getComponents() ) {
|
||||||
|
title = findTabTitle( child );
|
||||||
|
if( title != null )
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
protected void selectTab( int index ) {
|
protected void selectTab( int index ) {
|
||||||
tabPane.setSelectedIndex( index );
|
tabPane.setSelectedIndex( index );
|
||||||
ensureSelectedTabIsVisible();
|
ensureSelectedTabIsVisible();
|
||||||
|
|||||||
Reference in New Issue
Block a user