我的JScrollBar 的value 为什么总比Maximum值小10

CanFly 2001-09-13 05:13:26
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class Tests extends JPanel{
private JScrollBar sb;
public Tests() {
setLayout(new BorderLayout());
sb = new JScrollBar();
//sb.setMaximum(100);
//sb.setMinimum(0);

add(sb, BorderLayout.WEST);
sb.addAdjustmentListener(new AdjustmentListener() {

public void adjustmentValueChanged(AdjustmentEvent e) {
JScrollBar jsb = (JScrollBar)e.getAdjustable();

if(jsb.getValueIsAdjusting())
System.out.println("adjusting ...");
else
System.out.println(Integer.toString(e.getValue()));

}
});
}
}
class Test extends JFrame
{
public Test()
{
Container ctp=getContentPane();
ctp.setLayout(new BorderLayout());
ctp.add(new Tests(),"Center");
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public static void main (String args[])
{
Test mytest=new Test();
mytest.setVisible(true);
mytest.setSize(300,300);

}
}
...全文
99 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
masterz 2001-09-14
  • 打赏
  • 举报
回复
extent是那个滚动条(bar)代表的宽度
CanFly 2001-09-14
  • 打赏
  • 举报
回复
to masterz() 请教
sb.setValues(0,0,0,100);
我把extent只设成0 就可以了
extent是什么属性?
CanFly 2001-09-14
  • 打赏
  • 举报
回复
哦 谢谢
masterz 2001-09-13
  • 打赏
  • 举报
回复
10是缺省的extent值
masterz 2001-09-13
  • 打赏
  • 举报
回复
setValues
public void setValues(int newValue,
int newExtent,
int newMin,
int newMax)
Sets the four BoundedRangeModel properties after forcing the arguments to obey the usual constraints:
minimum <= value <= value+extent <= maximum

10是缺省的estent值

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧