Ho problemi a disegnare un JScrollPane. Voglio solo essere in grado di cambiare il colore del pollice e dello sfondo (e anche rimuovere i pulsanti di aumento/diminuzione). Finora ho provato quanto segue:Cambiare il colore del pollice e il colore di sfondo di un JScrollPane?
this.setBackground(new Color(0,0,0));
this.viewport.setBackground(new Color(0,0,0));
this.getViewport().setBackground(Color.BLACK);
this.setOpaque(false);
this.getVerticalScrollBar().setUI(new BasicScrollBarUI()
{
@Override
protected JButton createDecreaseButton(int orientation) {
return createZeroButton();
}
@Override
protected JButton createIncreaseButton(int orientation) {
return createZeroButton();
}
@Override
protected void configureScrollBarColors(){
}
});
this.getHorizontalScrollBar().setUI(new BasicScrollBarUI()
{
@Override
protected JButton createDecreaseButton(int orientation) {
return createZeroButton();
}
@Override
protected JButton createIncreaseButton(int orientation) {
return createZeroButton();
}
});
}
private JButton createZeroButton() {
JButton jbutton = new JButton();
jbutton.setPreferredSize(new Dimension(0, 0));
jbutton.setMinimumSize(new Dimension(0, 0));
jbutton.setMaximumSize(new Dimension(0, 0));
return jbutton;
}
anche
UIManager.put("ScrollBar.trackHighlightForeground", (new Color(57,57,57)));
UIManager.put("scrollbar", (new Color(57,57,57)));
UIManager.put("ScrollBar.thumb", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.thumbHeight", 2);
UIManager.put("ScrollBar.background", (new Color(57,57,57)));
UIManager.put("ScrollBar.thumbDarkShadow", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.thumbShadow", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.thumbHighlight", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.trackForeground", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.trackHighlight", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.foreground", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.shadow", new ColorUIResource(new Color(57,57,57)));
UIManager.put("ScrollBar.highlight", new ColorUIResource(new Color(57,57,57)));
Con tutto il codice di cui sopra ho un pollice buia con uno sfondo bianco. Stranamente se rimuovo le funzioni setUI, ottengo un pollice predefinito con uno sfondo scuro ..
Qualche idea?
Grazie
risolto ** * ** *
la funzione configureScrollBarColors sopra può essere utilizzato nel modo seguente:
@Override
protected void configureScrollBarColors(){
this.thumbColor = Color.GREEN;
}
Questo cambia il colore del pollice in verde.