Changing the color of Java custom scrollbar

Asked By 20 points N/A Posted on -
qa-featured

Dear Guys, I need a sample script for changing the color of Java custom scrollbox.

Please do the needful.

Thanks and Regards, Morison

SHARE
Answered By 5 points N/A #157426

Changing the color of Java custom scrollbar

qa-featured

Hello Morison

After doing a little research, I have found a code for you that will help you to change the color of the Java scrollbox. Also I have provided you with one link in case you need more information regarding this issue.

 public class ScrollBarTest extends javax.swing.JFrame {  

/** Creates new form ScrollBarTest */  

public ScrollBarTest() {  

initComponents();   

}  

private void initComponents() {//GEN-BEGIN:initComponents  

jTextArea1 = new javax.swing.JTextArea("Test",10,10);  

//jTextArea1.set  

jScrollPane1 = new javax.swing.JScrollPane(jTextArea1);  

button = new javax.swing.JButton("TestButton");  

addWindowListener(new java.awt.event.WindowAdapter() {  

public void windowClosing(java.awt.event.WindowEvent evt) {  

exitForm(evt);  

}  

});  

getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);  

getContentPane().add(button, java.awt.BorderLayout.SOUTH);  

java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();  

setSize(new java.awt.Dimension(200, 150));  

setLocation((screenSize.width-150)/2,(screenSize.height-100)/2);  

}//GEN-END:initComponents  

/** Exit the Application */  

private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm  

System.exit(0);  

}//GEN-LAST:event_exitForm  

/** 

* @param args the command line arguments 

*/  

public static void main(String args[]) {  

try{  

javax.swing.UIManager.put("ScrollBar.thumb", new javax.swing.plaf.ColorUIResource(33,129,176));  

javax.swing.UIManager.put("Button.foreground", new javax.swing.plaf.ColorUIResource(0,0,0));  

}catch(Exception e){  

e.printStackTrace();  

}  

ScrollBarTest test = new ScrollBarTest();  

test.show();  

}  

// Variables declaration – do not modify//GEN-BEGIN:variables  

private javax.swing.JScrollPane jScrollPane1;  

private javax.swing.JTextArea jTextArea1;  

private javax.swing.JButton button;  

// End of variables declaration//GEN-END:variables  

}

Java Color Code

I hope you will find this information useful.

Randolph

Related Questions