如何使可滚动到jPanel [英] How to make scrollable to jPanel

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

问题描述

我正在制作摇摆应用程序。我的jPanel的高度太高了。所以我想让这个面板可滚动。:
以下是我对我的要求的描述。

I am making swing application. And there is too much height of my jPanel. So I want to make this panel as scrollable.: Following is my description of my requirement.

我在一个jpanel中有四个jpanel我的意思是:

I have four jpanel in one jpanel I mean:

JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();

我正在添加 p2,p3,p4 p1 里面,如下面的输出:

I am adding p2, p3, p4 inside p1 like following output:

如上图所示,面板的高度高于计算机屏幕高度。所以我想通过滚动显示我的面板在计算机屏幕上的所有内容。

like above showing panel has more height than computer screen height. So I want to display all content of my panel on computer screen by scrolling.

我在这里搜索并发现了以下问题:

I searched here and found the following questions:

  • How to make a JPanel scrollable?
  • How do i get vertical scrolling to JPanel?

然而,答案并没有解决我的问题。

However, the answers did not solve myproblem.

推荐答案

在没有看到你的代码的情况下,我的猜测是你没有 JScrollpane 来提供你想要的可滚动行为。

Without seeing your code, my guess is that you don't have a JScrollpane to provide the scrollable behaviour you want.

JPanel mainPanel = new JPanel(); //This would be the base panel of your UI
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel p3=new JPanel();
JPanel p4=new JPanel();
JPanel newPanel = new JPanel();
newPanel.add(p1);
newPanel.add(p2);
newPanel.add(p3);
newPanel.add(p4);
JScrollPane pane = new JScrollPane(newPanel);
mainPanel.add(pane);

由于您使用NetBeans,请添加 JScrollpane 从调色板中,您将添加一个面板以包含其他4个面板。我想你也可以将4面板添加到 JScrollpane

Since you use NetBeans, add a JScrollpane from the palette in which you'll add a panel to contain the 4 others. I think you could also just add the 4 panel into the JScrollpane.

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

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