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

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

问题描述

我有问题.

我有一个 JFrame,其中包含一些 JTextField、JLabels、Jlist 和JButtons 现在我的框架的内容超过了屏幕区域,所以我想将一个 JScrollBar 附加到我的 JFrame 但我的滚动条不起作用.那么,谁能指导我如何使用 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天全站免登陆