Monday, 19 August 2013

JScrollBar customization

JScrollBar customization

I Have a problem. In my app I would like to customize scrollbar by
customizing Nimbus Look and Feel. If I create simple Java app in Netbeans
it's working. But the problem is when I enter the same few lines of code
in Netbeans Platform app customization is only at arrow buttons and the
thumb and track are still the same.
final Color sedaDialog = new Color(55, 55, 55);
final Color bila = new Color(255, 255, 255);
NimbusLookAndFeel laf = null;
try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
laf = (NimbusLookAndFeel) UIManager.getLookAndFeel();
} catch (Exception e) {
}
laf.getDefaults()
.put("ScrollBar:\"ScrollBar.button\"[Enabled].foregroundPainter",
new Painter<JButton>() {
@Override
public void paint(Graphics2D gd, JButton t, int w, int h) {
gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
gd.setColor(sedaDialog);
gd.fillRect(0, 0, w, h);
gd.setColor(bila);
int[] x = {w - 6, w - 6, 6};
int[] y = {h - 3, 4, h / 2 + 1};
gd.fillPolygon(x, y, 3);
}
});
laf.getDefaults()
.put("ScrollBar:\"ScrollBar.button\"[MouseOver].foregroundPainter",
new Painter<JButton>() {
@Override
public void paint(Graphics2D gd, JButton t, int w, int h) {
gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
gd.setColor(sedaDialog);
gd.fillRect(0, 0, w, h);
gd.setColor(bila);
int[] x = {w - 6, w - 6, 6};
int[] y = {h - 3, 4, h / 2 + 1};
gd.fillPolygon(x, y, 3);
}
});
laf.getDefaults()
.put("ScrollBar:\"ScrollBar.button\"[Pressed].foregroundPainter",
new Painter<JButton>() {
@Override
public void paint(Graphics2D gd, JButton t, int w, int h) {
gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
gd.setColor(sedaDialog);
gd.fillRect(0, 0, w, h);
gd.setColor(bila);
int[] x = {w - 6, w - 6, 6};
int[] y = {h - 3, 4, h / 2 + 1};
gd.fillPolygon(x, y, 3);
}
});
laf.getDefaults()
.put("ScrollBar:ScrollBarThumb[Enabled].backgroundPainter",
new Painter<JComponent>() {
@Override
public void paint(Graphics2D gd, JComponent t, int w, int h) {
gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
gd.setColor(sedaDialog);
gd.fillRect(0, 0, w, h);
gd.setColor(bila);
gd.fillRoundRect(3, 4, w - 5, h - 8, 10, 10);
}
});
laf.getDefaults()
.put("ScrollBar:ScrollBarThumb[MouseOver].backgroundPainter",
new Painter<JComponent>() {
@Override
public void paint(Graphics2D gd, JComponent t, int w, int h) {
gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
gd.setColor(sedaDialog);
gd.fillRect(0, 0, w, h);
gd.setColor(bila);
gd.fillRoundRect(3, 4, w - 5, h - 8, 10, 10);
}
});
laf.getDefaults()
.put("ScrollBar:ScrollBarThumb[Pressed].backgroundPainter",
new Painter<JComponent>() {
@Override
public void paint(Graphics2D gd, JComponent t, int w, int h) {
gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
gd.setColor(sedaDialog);
gd.fillRect(0, 0, w, h);
gd.setColor(bila);
gd.fillRoundRect(3, 4, w - 5, h - 8, 10, 10);
}
});
laf.getDefaults()
.put("ScrollBar:ScrollBarTrack[Enabled].backgroundPainter",
new Painter<JComponent>() {
@Override
public void paint(Graphics2D gd, JComponent t, int w, int h) {
gd.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
gd.setColor(sedaDialog);
gd.fillRect(0, 0, w, h);
}
});
laf.getDefaults()
.put(
"ScrollBar:\"ScrollBar.button\".size", 20);
This is code I used and I know it's ok and works. But I have no idea why
it's not working in Netbeans Platform. Thx a lot for every reply. :-)

No comments:

Post a Comment