📄 showjscrollbar.java
字号:
import javax.swing.JFrame;
import java.awt.FlowLayout;
import javax.swing.JScrollBar;
import javax.swing.JLabel;
import java.awt.event.AdjustmentListener;
import java.awt.event.AdjustmentEvent;
class ShowJScrollBar extends JFrame implements AdjustmentListener{
FlowLayout flowLayout1=new FlowLayout();
JScrollBar jScrollBar1=new JScrollBar(JScrollBar.HORIZONTAL);
JScrollBar jScrollBar2=new JScrollBar(JScrollBar.VERTICAL,10,50,10,250);
JLabel jLabel1=new JLabel("0");
JLabel jLabel2=new JLabel("10");
ShowJScrollBar(){
super("滚动条示例");
setSize(200,150);
setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(flowLayout1);
this.getContentPane().add(jScrollBar1);
this.getContentPane().add(jLabel1);
this.getContentPane().add(jScrollBar2);
this.getContentPane().add(jLabel2);
jScrollBar1.addAdjustmentListener(this);
jScrollBar2.addAdjustmentListener(this);
show();
}
public void adjustmentValueChanged(AdjustmentEvent e){
int i;
if(e.getSource()==jScrollBar1){
i=jScrollBar1.getValue();
jLabel1.setText(""+i);
}
else if(e.getSource()==jScrollBar2){
i=jScrollBar2.getValue();
jLabel2.setText(""+i);
}
}
public static void main(String[] args){
ShowJScrollBar showJScroll1=new ShowJScrollBar();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -