布局管理器和滚动窗格的一些问题,不显示对象
我的应用程序遇到问题。我希望动态创建几个“选项卡式”滚动窗格,其中包含半大量称为“ImageLabels”的对象,这些对象只是带有(您猜对了)图像的标签。
我的大部分 gui 都是在 Netbeans 中制作的,因为它是半复杂的,而且我自己也不太懂。
我的问题是这样的:当添加滚动窗格对象(包含带有 GridLayout 的 JPanel)时,以及在尝试将图像标签添加到带有布局的 JPanel 后(我的构造函数设置为“new GridLayout(0, 5, 5, 5);" 无限行、5 列、5 pxls 空间。)没有显示任何内容,滚动面板也不会进入“滚动”模式。
我完全不知所措,一整天都在尝试不同的布局。这是我的一些代码...
ImageLabel 对象的构造函数..
addMouseListener(this);
setVisible(true);
setPreferredSize(new Dimension(32, 32));
我如何设置我的tileHolderPanel JPanel(包含ImageLabels的面板)
myLayout = new GridLayout(0, 5, 5, 5);
tileHolderPanel.setLayout(myLayout);
,并在构造完我希望添加到每个面板的所有ImageLabels之后,我只需做
tileHolderPanel.add(label);
如果重要的话,我的 TileHolderPanel 位于 JPanel 内的滚动窗格内,并且它们具有 Netbeans 生成的默认 GroupLayouts。
谢谢你, -卢克
I'm having an issue in my application. I wish to dynamically create several "tabbed" scrollpanes that hold a semi-large amount of objects called "ImageLabels", which are just labels with (you guessed it) images on them.
I made most of my gui in Netbeans, as it is semi-complicated and I'm too nooby to do it myself.
My problem is this: When adding my scrollpane objects (that contain a JPanel with a GridLayout), and after I attempt to add my imagelabels to the JPanel with the layout (my constructor is set to "new GridLayout(0, 5, 5, 5);" which is unlimited rows, 5 columns, with 5 pxls of space.) nothing shows up, nor does the scrollpanel go into "scroll" mode.
I am completely at a loss and have been trying all day with different layouts. Here's some code I have...
Constructor of the ImageLabel object..
addMouseListener(this);
setVisible(true);
setPreferredSize(new Dimension(32, 32));
How I set up my tileHolderPanel JPanel (the panel holding the ImageLabels)
myLayout = new GridLayout(0, 5, 5, 5);
tileHolderPanel.setLayout(myLayout);
and after constructing all of the ImageLabels I wish to add to each panel, I simply do
tileHolderPanel.add(label);
If it matters, my TileHolderPanel is inside of a scrollpane which is inside a JPanel,and they have the default GroupLayouts which Netbeans generates.
Thank you,
-Luke
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个可用于比较您的代码的工作示例。
Here's a working example with which to compare your code.
当您将组件添加到可见 GUI 时,基本代码应该是:
如果您需要更多帮助,那么您需要发布 SSCCE。
When you add components to a visible GUI the basic code should be:
If you need more help then you need to post an SSCCE.