如何设置滚动条的长度

xiongwenhua365 2008-10-15 04:53:34

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class AdjustTest implements AdjustmentListener
{
JFrame jf=new JFrame("adjustmentevent测试");

Panel p=new Panel();
Scrollbar sb;
public AdjustTest()
{
sb=new Scrollbar(Scrollbar.VERTICAL , 0,20, 0,500);
sb.setSize(50,50);//这条语句好像没用啊,
sb.addAdjustmentListener(this);
p.add(sb);
jf.add(p);
jf.setSize(200,200);
jf.setLocation(300,300);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void adjustmentValueChanged(AdjustmentEvent e)
{
Scrollbar ss=(Scrollbar)e.getAdjustable();
System.out.println(ss.getValue());
}
public static void main(String[] args)
{
AdjustTest at=new AdjustTest();
}
}
滚动条不够长,看起不不舒服,如何才能把它变长了点了,
...全文
1696 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
huoyin 2008-10-16
  • 打赏
  • 举报
回复


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class AdjustTest implements AdjustmentListener {
JFrame jf = new JFrame("adjustmentevent测试");

Panel p = new Panel();

Scrollbar sb;

public AdjustTest() {
sb = new Scrollbar(Scrollbar.VERTICAL, 0, 20, 0, 500);
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.weighty = 1.0;
sb.addAdjustmentListener(this);
p.setLayout(new GridBagLayout());
p.add(sb, c);
jf.add(p);
jf.setSize(200, 200);
jf.setLocation(300, 300);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void adjustmentValueChanged(AdjustmentEvent e) {
Scrollbar ss = (Scrollbar) e.getAdjustable();
System.out.println(ss.getValue());
}

public static void main(String[] args) {
AdjustTest at = new AdjustTest();
}
}

java__king 2008-10-15
  • 打赏
  • 举报
回复
没用过,学习.
justinavril 2008-10-15
  • 打赏
  • 举报
回复
它会自动调节的吧...你可以设置一个首选的大小:setPreferredSize
bluesmile979 2008-10-15
  • 打赏
  • 举报
回复
setpreffersize()?记不太清楚大概是这样的名字。

setminsize()

一般以上两个可以控制大小,



setmaxsize()
horizonlyhw 2008-10-15
  • 打赏
  • 举报
回复

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class AdjustTest implements AdjustmentListener
{
JFrame jf=new JFrame("adjustmentevent測試");

Panel p=new Panel();

Scrollbar sb;
public AdjustTest ()
{
p.setLayout(null);
sb=new Scrollbar(Scrollbar.VERTICAL , 0,20, 0,500);
sb.setBounds(new Rectangle(0,0,10,150));
sb.addAdjustmentListener(this);
p.add(sb);
jf.add(p);
jf.setSize(200,200);
jf.setLocation(300,300);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void adjustmentValueChanged(AdjustmentEvent e)
{
Scrollbar ss=(Scrollbar)e.getAdjustable();
System.out.println(ss.getValue());
}
public static void main(String[] args)
{
AdjustTest at=new AdjustTest();
}
}

xiongwenhua365 2008-10-15
  • 打赏
  • 举报
回复

62,615

社区成员

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

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