Hi,
Is there a way to specify the maximum width of a tab component in an eclipse theme?
I’m using EclipseTheme with a RectGradientPainter as a TAB_PAINTER and I want to limit the width of my TabComponent.
Thx
Hi,
Is there a way to specify the maximum width of a tab component in an eclipse theme?
I’m using EclipseTheme with a RectGradientPainter as a TAB_PAINTER and I want to limit the width of my TabComponent.
Thx
There is no code to shorten the title-text, e.g. replace some characters with “…”. So while you can write some code to restrict the width, it will not look nice… you would have to implement your own tab to make this one look good.
Here an example:
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.border.Border;
import bibliothek.extension.gui.dock.theme.EclipseTheme;
import bibliothek.extension.gui.dock.theme.eclipse.stack.EclipseTabPane;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.BorderedComponent;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.InvisibleTab;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.InvisibleTabPane;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.RectGradientPainter;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.TabComponent;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.TabPainter;
import bibliothek.extension.gui.dock.theme.eclipse.stack.tab.TabPanePainter;
import bibliothek.gui.DockController;
import bibliothek.gui.Dockable;
import bibliothek.gui.dock.DefaultDockable;
import bibliothek.gui.dock.SplitDockStation;
import bibliothek.gui.dock.station.split.SplitDockProperty;
public class HideTitleExample {
public HideTitleExample(){
JFrame frame = new JFrame();
frame.setSize( 700, 500 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
final DockController controller = new DockController();
final DefaultDockable firstDockable = new DefaultDockable( "First Dockable" );
final DefaultDockable secondDockable = new DefaultDockable( "Second Dockable" );
final DefaultDockable thirdDockable = new DefaultDockable( "Third Dockable" );
EclipseTheme theme = new EclipseTheme();
controller.setTheme( theme );
controller.getProperties().set( EclipseTheme.TAB_PAINTER, new RestrictedTabPainter() );
SplitDockStation splitDockStation = new SplitDockStation();
controller.add( splitDockStation );
splitDockStation.drop( firstDockable );
splitDockStation.drop( secondDockable, SplitDockProperty.SOUTH );
splitDockStation.drop( thirdDockable, SplitDockProperty.EAST );
frame.add( splitDockStation, BorderLayout.CENTER );
frame.setVisible( true );
}
public static void main( String[] args ){
new HideTitleExample();
}
private static class RestrictedTabPainter implements TabPainter{
@Override
public TabPanePainter createDecorationPainter( EclipseTabPane pane ){
return RectGradientPainter.FACTORY.createDecorationPainter( pane );
}
@Override
public InvisibleTab createInvisibleTab( InvisibleTabPane pane, Dockable dockable ){
return RectGradientPainter.FACTORY.createInvisibleTab( pane, dockable );
}
@Override
public TabComponent createTabComponent( EclipseTabPane pane, Dockable dockable ){
return new RestrictedPainter( pane, dockable );
}
@Override
public Border getFullBorder( BorderedComponent owner, DockController controller, Dockable dockable ){
return RectGradientPainter.FACTORY.getFullBorder( owner, controller, dockable );
}
}
private static class RestrictedPainter extends RectGradientPainter{
private int maxWidth = 50;
public RestrictedPainter( EclipseTabPane pane, Dockable dockable ){
super( pane, dockable );
}
@Override
public Dimension getMinimumSize(){
Dimension original = super.getMinimumSize();
return new Dimension( Math.min( maxWidth, original.width ), original.height );
}
@Override
public Dimension getPreferredSize(){
Dimension original = super.getPreferredSize();
return new Dimension( Math.min( maxWidth, original.width ), original.height );
}
}
}```