The JTableHaeder has no 'pressed' highlighting by default. (Nimbus)
NimbusDefaults says it has a default [Pressed] background painter.
What should I do, to see this when i click on the TableHeader?
UPDATE 1
The NimbusStyle.getExtendedState
returns the PRESSED on mouseDown correctly. But the NimbusStyle.getBackgroundPainter(SynthContext)
returns null
cause there is an null
in the NimbusStyle.Values
cache for the CacheKey "backgroundPainter$$instance" with this state.
What is wrong there?
UPDATE 2
My example shows a JTableHeader and a JScrollBar with an 'Pressed Behavior'.
For the JScrollBar my putClientProperty( "Nimbus.State" )
works with a repaint problem.
public class Header extends JPanel{
public Header() {
super(new BorderLayout());
JTableHeader header = new JTable(5, 3).getTableHeader();
JScrollBar scroll = new JScrollBar(JScrollBar.HORIZONTAL);
add(header, BorderLayout.NORTH);
add(scroll, BorderLayout.SOUTH);
scroll.addMouseListener( new PressedBehavior() );
header.addMouseListener( new PressedBehavior() );
}
static public void main( String[] s ) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {
JFrame f = new JFrame("Nimbus Pressed Example");
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.setBounds( 150, 150, 300, 200 );
f.getContentPane().add( new Header() );
f.setVisible( true );
}
});
} catch( Exception fail ) { /*ignore*/ }
}
private class PressedBehavior extends MouseAdapter {
@Override
public void mouseReleased( MouseEvent e ) {
JComponent source = (JComponent)e.getComponent();
source.putClientProperty( "Nimbus.State", null );
}
@Override
public void mousePressed( MouseEvent e ) {
JComponent source = (JComponent)e.getComponent();
source.putClientProperty( "Nimbus.State", "Pressed" );
//source.invalidate();
//source.repaint();
}
}
}