[QUOTE=Beni]Thats going to need a workaround… I see two useful solutions.
- Solution
Every pair Dockable and DockTitle is put onto a DockableDisplayer. We can write our own displayer and give it the necessary behavior to hide invisible titles.
- perfectly save method, chances of unexpected side effects are very low
- Needs to be done for each DockTheme
public static void main( String[] args ){
DockController controller = new DockController();
SplitDockStation station = new SplitDockStation();
station.getDisplayerFactory().setDelegate( new BasicDisplayerFactory(){
@Override
protected BasicDockableDisplayer create( Dockable dockable, DockTitle title, Location location ) {
return new BetterDisplayer( dockable, title, location );
}
});
JFrame frame = new JFrame( "Demo" );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setBounds( 20, 20, 400, 400 );
frame.add( station.getComponent() );
controller.add( station );
SplitDockGrid grid = new SplitDockGrid();
grid.addDockable( 0, 0, 1, 1, createDockable( "A" ) );
grid.addDockable( 0, 1, 1, 1, createDockable( "B" ) );
station.dropTree( grid.toTree() );
frame.setVisible( true );
}
public static Dockable createDockable( String title ){
final JToggleButton change = new JToggleButton( "Show title" );
change.setSelected( true );
final DefaultDockable dockable = new DefaultDockable( change, title );
change.addActionListener( new ActionListener(){
public void actionPerformed( ActionEvent e ) {
boolean show = change.isSelected();
for( DockTitle title : dockable.listBoundTitles() )
title.getComponent().setVisible( show );
}
});
return dockable;
}
private static class BetterDisplayer extends BasicDockableDisplayer{
public BetterDisplayer( Dockable dockable, DockTitle title, Location location ){
super( dockable, title, location );
}
@Override
public void doLayout() {
if( getTitle() == null || getTitle().getComponent().isVisible() ){
super.doLayout();
}
else{
Dockable dockable = getDockable();
if( dockable != null ){
Insets insets = getInsets();
if( insets == null )
insets = new Insets(0,0,0,0);
int x = insets.left;
int y = insets.top;
int width = getWidth() - insets.left - insets.right;
int height = getHeight() - insets.top - insets.bottom;
width = Math.max( 0, width );
height = Math.max( 0, height );
getComponent( dockable ).setBounds( x, y, width, height );
}
}
}
}
}```
[/QUOTE]
Hi,
I have been using this solution to remove the DockTitle (when there is only one dockable) very successfully. However, after upgrading to DockingFrames 1.0.8 p2, it started failing.
Scenario:
There are 2 dockables which are docked. I close one of them, so that there is only one dockable remaining. This dockable does not have a title but the area occupied by the title is not taken up by the dockable and appears as a blank area. Also the area on the opposite side of the previous dockable (equal in size to the previous dockable) remains blank.
I modified the code so that super.doLayout(...) is always called.
private static class BetterDisplayer extends BasicDockableDisplayer{
public BetterDisplayer( Dockable dockable, DockTitle title, Location location ){
super( dockable, title, location );
}
@Override
public void doLayout() {
//changed this line so that super.doLayout() is always called
super.doLayout();
if( getTitle() == null || getTitle().getComponent().isVisible() ){
...
}
else{
Dockable dockable = getDockable();
if( dockable != null ){
Insets insets = getInsets();
if( insets == null )
insets = new Insets(0,0,0,0);
int x = insets.left;
int y = insets.top;
int width = getWidth() - insets.left - insets.right;
int height = getHeight() - insets.top - insets.bottom;
width = Math.max( 0, width );
height = Math.max( 0, height );
getComponent( dockable ).setBounds( x, y, width, height );
}
}
}
}
}```
This change elliminated the error of blank area being shown to the side of the dockable. However, the problem with the titlebar still remains. So now the titlebar is not shown when there is one dockable, but the area appears as blank area.
I debugged the code to check the bounds which I am giving to the Dockable. I see that when the title is being displayed the height of the component is 476 and the titlebar (I think) occupied 24 pixels in height. When only one dockable is displayed I can see that the bounds are being set properly (height is being set to 500) but somehow the component does not seem to be accepting the height of 500 and still renders at a height of 476.
Has anything changed in the new release that might be causing this problem?
Thanks a lot in advance for your time and effort.