从代码(Java6)
import com.sun.java.swing.Painter;
import java.awt.Color;
import java.awt.Graphics2D;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class ScrollDemo extends JFrame {
private static final long serialVersionUID = 1L;
public ScrollDemo() {
JTextField field = new JTextField();
String[] columnNames = {"Column"};
Object[][] data = {
{"A"}, {"B"}, {"C"}, {"D"}, {"E"}, {"F"},
{"A"}, {"B"}, {"C"}, {"D"}, {"E"}, {"F"},
{"A"}, {"B"}, {"C"}, {"D"}, {"E"}, {"F"},
{"A"}, {"B"}, {"C"}, {"D"}, {"E"}, {"F"},
{"A"}, {"B"}, {"C"}, {"D"}, {"E"}, {"F"},};
add(new JScrollPane(new JTable(data, columnNames)));
pack();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception fail) {
}
UIManager.getLookAndFeelDefaults().put("ScrollBar:ScrollBarThumb[Enabled].backgroundPainter",
new FillPainter(new Color(255, 169, 191)));
UIManager.getLookAndFeelDefaults().put("ScrollBar:ScrollBarThumb[MouseOver].backgroundPainter",
new FillPainter(new Color(127, 255, 191)));
UIManager.getLookAndFeelDefaults().put("ScrollBar:ScrollBarTrack[Enabled].backgroundPainter",
new FillPainter(new Color(0, 212, 255)));
UIManager.getLookAndFeelDefaults().put("ScrollBar:\"ScrollBar.button\".size", 20);
//UIManager.getLookAndFeelDefaults().put("ScrollBar.decrementButtonGap", 10);
//UIManager.getLookAndFeelDefaults().put("ScrollBar.incrementButtonGap", 10);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
ScrollDemo scrollDemo = new ScrollDemo();
}
});
}
}
class FillPainter implements Painter<JComponent> {
private final Color color;
public FillPainter(Color c) {
color = c;
}
@Override
public void paint(Graphics2D g, JComponent object, int width, int height) {
g.setColor(color);
g.fillRect(0, 0, width - 1, height - 1);
}
}