-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddScrollBarToJFrame.java
35 lines (28 loc) · 1.24 KB
/
AddScrollBarToJFrame.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package KevinBaconGame;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class AddScrollBarToJFrame {
public static void main(String[] args) {
final JFrame frame = new JFrame("JScrollbar Demo");
final JLabel label = new JLabel( );
JScrollBar hbar=new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 500);
JScrollBar vbar=new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 500);
class MyAdjustmentListener implements AdjustmentListener {
public void adjustmentValueChanged(AdjustmentEvent e) {
label.setText("Slider's position is " + e.getValue());
frame.repaint();
}
}
hbar.addAdjustmentListener(new MyAdjustmentListener( ));
vbar.addAdjustmentListener(new MyAdjustmentListener( ));
frame.setLayout(new BorderLayout( ));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300,200);
frame.getContentPane().add(label);
frame.getContentPane().add(hbar, BorderLayout.SOUTH);
frame.getContentPane().add(vbar, BorderLayout.EAST);
frame.getContentPane().add(label, BorderLayout.CENTER);
frame.setVisible(true);
}
}