gabibau
15. Dezember 2016 um 06:29
1
I have an application that shows content in several DefaultSingleCDockable tabs.
Sometimes this cotents are GLJPanel based, and they have an issue that makes other components disappear in a specific situation. On this cases, I have to rapaint() part of the interface. The only thing I still can’t get repainted is the Tab-Title.
I’m looking for something like “dockable.repaint()”, or “dockable.getTitleTab().repaint()”.
Changing the text with dockable.setTitleText(…) does the trick, IF I really change the text to something else, but I need to keep the same text. If I do dockable.setTitleText(dockable.getTitleText()), It does not repaint.
Any tip?
Beni
17. Dezember 2016 um 07:37
2
Interesting issue you have.
For most themes you can iterate through the “representatives” of a Dockable
to find the Component
that paints the tab. Like in the example below.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import bibliothek.gui.dock.DockElementRepresentative;
import bibliothek.gui.dock.common.CControl;
import bibliothek.gui.dock.common.CGrid;
import bibliothek.gui.dock.common.DefaultSingleCDockable;
import bibliothek.gui.dock.common.SingleCDockable;
import bibliothek.gui.dock.common.action.CButton;
import bibliothek.gui.dock.common.intern.CDockable;
import bibliothek.gui.dock.common.theme.ThemeMap;
public class RepaintExample {
public static void main( String[] args ) {
JFrame frame = new JFrame( "Test" );
CControl control = new CControl( frame );
control.setTheme( ThemeMap.KEY_ECLIPSE_THEME );
frame.add( control.getContentArea() );
CGrid grid = new CGrid( control );
grid.add( 0, 0, 1, 1, dockable( control, "a", "Aaaa" ) );
grid.add( 0, 0, 1, 1, dockable( control, "b", "Bbbb" ) );
control.getContentArea().deploy( grid );
frame.setBounds( 50, 50, 800, 800 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible( true );
}
private static SingleCDockable dockable( CControl control, String id, String title ){
DefaultSingleCDockable dockable = new DefaultSingleCDockable( id, title );
CButton button = new CButton();
button.setText( "Repaint" );
button.setShowTextOnButtons( true );
button.addActionListener( new RepaintAction( control, dockable ) );
dockable.addAction( button );
return dockable;
}
private static class RepaintAction implements ActionListener{
private CControl control;
private CDockable dockable;
public RepaintAction( CControl control, CDockable dockable ){
this.control = control;
this.dockable = dockable;
}
@Override
public void actionPerformed( ActionEvent e ) {
DockElementRepresentative[] representatives = control.getController().getRepresentatives( dockable.intern() );
for( DockElementRepresentative view : representatives ){
System.out.println( String.format( "repainting %s: %s", view.getClass().getSimpleName(), view.toString() ));
view.getComponent().repaint();
}
}
}
}
The default theme uses a JTabbedPane
, and the tabs there are not that easy to access. Perhaps repainting the JTabbedPane
might help, like this:
@Override
public void actionPerformed( ActionEvent e ) {
JTabbedPane tabbed = (JTabbedPane) SwingUtilities.getAncestorOfClass( JTabbedPane.class, dockable.intern().getComponent() );
if( tabbed != null ) {
for( int i = 0, n = tabbed.getTabCount(); i < n; i++ ) {
Rectangle tabBounds = tabbed.getBoundsAt( i );
if( tabBounds != null ) {
System.out.println( String.format( "repainting %d, %s", i, tabBounds ) );
tabbed.repaint( tabBounds );
}
}
}
}