如何在Java中的不同JPanel中使用滚动条显示不同的图像? [英] How to display different image with scroll bar in different JPanel in Java?

查看:106
本文介绍了如何在Java中的不同JPanel中使用滚动条显示不同的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我试图通过使用Java Swing窗口浏览对话框来在不同的Jpanel中显示两个图像.但是浏览第二张图像后,面板没有处于其位置.同样,没有滚动条的图像尺寸也会变大.我必须使用哪种类型的布局.每当浏览具有固定大小和滚动条的新布局时,都需要更改图像.请发表您的想法来帮助我.


我已经通过网格布局将一个面板分成了fout部分.我需要在顶部的两个部分中显示两个图像.
如果mge大小不同,则图像隐藏在面板内部.如果我使用滚动条,则无法对齐
正确地我应该使用哪种类型的布局.

Hi,
I''m trying to show two images in different Jpanel by browsing dialog using Java Swing window. But the panels are not being in its position after browsing the second image. Also the size of the image getting large without scroll bar. What type of layout i have to use.i need to change the image whenever browsing new one with a fixed size and with scroll bar. Please help me by posting your ideas.

Hi,
i have splitted one panel into fout parts by grid layout. i need to show two images in top two parts.
If the mge size is different the image is hiding inside of panel. If i used scroll bar its not aligning
properly what type of layout should i use. how to set scroll bar for inner panels.

推荐答案

javax.swing.JPanel放在javax.swing.JScrollPane上,如下所示:
Put your javax.swing.JPanel on a javax.swing.JScrollPane like this:
JPanel pnlImage = new JPanel(new BorderLayout());
JScrollPane spnImage = new JScrollPane(pnlImage);


然后,不要将面板pnlImage放置在容器或框架上,而是将滚动窗格spnImage放置在容器或框架上.


Then instead of placing the panel pnlImage on your container or frame, place the scroll pane spnImage on it.


从上一个答案中,您得到了巨大的提示.使用ScrollPanel,所有内容都在面板上,并为您管理滚动.
From the previuous answer you were given a HUGE clue. Use a ScrollPanel, everything goes on the panel and it manages the scrolling for you.


这篇关于如何在Java中的不同JPanel中使用滚动条显示不同的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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