第二行gridbaglayout滚动出容器 [英] Second row of gridbaglayout scrolling out of container
问题描述
我正在尝试实现类似于轮播的布局.它需要水平添加图像,并在第二行中添加一个复选框字段.我在jscrollpane中有一个面板,并且各个图像作为标签添加到了面板中.请查看屏幕截图.
I am trying to achieve a layout similar to that of a carousel. It needs to have images added horizontally with a checkbox field in the second row. I have a panel within a jscrollpane and individual images are added to the panel as labels. Please see screen shot.
当我滚动窗格时,包含图像的第一行位于面板内..但是,如果您注意到复选框的第二行,它将滚动出面板.这是代码...
When I scroll the pane , the first row containing the images stays well within the panel..but if you notice the second row of checkboxes , it scrolls out of the panel. Here is the code ...
JLabel lab1=new JLabel();
for (int ii=0; ii<imageFiles.length; ii++) {
GridBagConstraints constraint = new GridBagConstraints();
lab1 = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
constraint.gridx = ii;
constraint.gridy =0;
jPanel9.add(lab1,constraint);
}
for (int ii=0; ii<imageFiles.length; ii++) {
GridBagConstraints constraint1 = new GridBagConstraints();
constraint1.anchor = GridBagConstraints.SOUTH;
chkbox = new Checkbox("asdasdada");
constraint1.gridx = ii;
constraint1.gridy =1;
jPanel9.add(chkbox, constraint1);
}
不确定是什么问题..非常感谢任何帮助..谢谢..
Not sure what is wrong..Any help is much appreciated..Thanks..
推荐答案
问题是您将AWT组件(重量级)与Swing组件(轻量级)混合在一起.我有2条建议:
The problem is that you are mixing AWT components (heavyweight) with Swing components (lightweight). I have 2 recommendations:
- 请勿混合重量级和轻量级组件
- 尝试尽可能多地使用轻量级组件
因此,在您的代码中,将Checkbox
替换为JCheckbox
,它应该可以正常工作.
So in your code, replace Checkbox
by JCheckbox
and it should work just fine.
这篇关于第二行gridbaglayout滚动出容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!