如何使用JScrollbar滚动我的JFrame? [英] how can I scroll my JFrame using the JScrollbar?

查看:181
本文介绍了如何使用JScrollbar滚动我的JFrame?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了问题。

我有一个带有一些JTextFields,JLabels,Jlists& JButtons现在我的框架的内容超过了屏幕区域,所以我想将JScrollBar附加到我的JFrame,但我的srollbar不起作用。那么,任何人都可以指导我如何使用JScrollbar滚动我的JFrame吗?

I have a JFrame with some JTextFields, JLabels, Jlists & JButtons now the contents of my frame is more than the screen area so I want to attach a JScrollBar to my JFrame but my srollbar does not work. So, can anyone please guide me on how I can scroll my JFrame using the JScrollbar?

推荐答案


  1. 将所有组件放在一个面板中(而不是放在JFrame中)

  2. 将此面板添加到JScrollPane

  3. 将JScrollPane添加到框架中。

我应该是这样的:

JPanel container = new JPanel();
container.add(panel1);
container.add(Panel2);
JScrollPane jsp = new JScrollPane(container);
frame.add(jsp);

这篇关于如何使用JScrollbar滚动我的JFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆