为什么在JPanel上加滚动条不成功啊,滚动条不能滚动

Kittysimida 2014-12-26 10:58:58
void add()
{
CookiePanel rightpanel=new CookiePanel();
JScrollPane scroll = new JScrollPane();
scroll.setBounds(200, 120, 770, 590);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setBackground(null);
scroll.setOpaque(false);
scroll.getViewport().setOpaque(false);
scroll.setBorder(null);
this.add(scroll);
scroll.add(rightpanel);
}

public class CookiePanel extends JPanel{
public CookiePanel()
{

this.setBounds(0,0,800,990);
//this.setBounds(200, 120, 800, 550);
this.setBackground(null);
this.setOpaque(false);
this.setPreferredSize(null);
//this.setLayout(new FlowLayout(FlowLayout.LEFT,30,20));
this.setLayout(null);
}
}
...全文
149 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hike1992 2014-12-26
  • 打赏
  • 举报
回复
scroll.add(rightpanel); 把这句改成 scroll.setViewportView(rightpanel); JScrollPanel是不能用.add(),加组件的
Inhibitory 2014-12-26
  • 打赏
  • 举报
回复
JScrollPane scroll = new JScrollPane(rightpanel);

62,621

社区成员

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

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