Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scroll;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import java.awt.event.AdjustmentEvent;
- import java.awt.FlowLayout;
- import java.awt.Color;
- import javax.swing.JButton;
- import javax.swing.JScrollBar;
- import javax.swing.JLabel;
- import javax.swing.JFrame;
- import java.awt.event.AdjustmentListener;
- public class scroll {
- private JFrame frmScrollbarColourChange;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- scroll window = new scroll();
- window.frmScrollbarColourChange.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the application.
- */
- public scroll() {
- initialize();
- }
- /**
- * Initialize the contents of the frame.
- */
- private void initialize() {
- frmScrollbarColourChange = new JFrame();
- frmScrollbarColourChange.setTitle("Scrollbar colour change");
- frmScrollbarColourChange.setBounds(100, 100, 653, 358);
- frmScrollbarColourChange.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frmScrollbarColourChange.getContentPane().setLayout(null);
- JLabel lblNewLabel = new JLabel(" ");
- lblNewLabel.setBounds(126, 52, 368, 81);
- frmScrollbarColourChange.getContentPane().add(lblNewLabel);
- JScrollBar r = new JScrollBar();
- r.setOrientation(JScrollBar.HORIZONTAL);
- r.setMaximum(255);
- r.setBounds(226, 164, 268, 17);
- frmScrollbarColourChange.getContentPane().add(r);
- JScrollBar g = new JScrollBar();
- g.setOrientation(JScrollBar.HORIZONTAL);
- g.setMaximum(255);
- g.setBounds(226, 207, 268, 17);
- frmScrollbarColourChange.getContentPane().add(g);
- JScrollBar b = new JScrollBar();
- b.setMaximum(255);
- b.setOrientation(JScrollBar.HORIZONTAL);
- b.setBounds(226, 249, 268, 17);
- frmScrollbarColourChange.getContentPane().add(b);
- JLabel lblNewLabel_1 = new JLabel("Red");
- lblNewLabel_1.setBounds(143, 167, 46, 14);
- frmScrollbarColourChange.getContentPane().add(lblNewLabel_1);
- JLabel lblNewLabel_2 = new JLabel("Green");
- lblNewLabel_2.setBounds(143, 207, 46, 14);
- frmScrollbarColourChange.getContentPane().add(lblNewLabel_2);
- JLabel lblNewLabel_3 = new JLabel("Blue");
- lblNewLabel_3.setBounds(143, 252, 46, 14);
- frmScrollbarColourChange.getContentPane().add(lblNewLabel_3);
- r.addAdjustmentListener(new AdjustmentListener() {
- public void adjustmentValueChanged(AdjustmentEvent e) {
- lblNewLabel.setBackground(new Color(r.getValue(),g.getValue(),b.getValue()));
- lblNewLabel.setOpaque(true);
- }
- });
- g.addAdjustmentListener(new AdjustmentListener() {
- public void adjustmentValueChanged(AdjustmentEvent e) {
- lblNewLabel.setBackground(new Color(r.getValue(),g.getValue(),b.getValue()));
- lblNewLabel.setOpaque(true);
- }
- });
- b.addAdjustmentListener(new AdjustmentListener() {
- public void adjustmentValueChanged(AdjustmentEvent e) {
- lblNewLabel.setBackground(new Color(r.getValue(),g.getValue(),b.getValue()));
- lblNewLabel.setOpaque(true);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment