在 Swing 中更改 CardLayout 的大小
由于 CardLayout 的大小固定,我无法在 Swing 中对齐网格面板。
我有一个 gridPanel gpTenderTypes,我使用了卡片布局。
gpTenderTypes.setLayout(new CardLayout());
当单击按钮时,卡片将发生变化,并且将调用该类(例如,当单击信用卡按钮时,将显示网格面板中的信用卡并调用 Card1() 对象。
gpTenderTypes.add(new Cash1(), DBConstants.TENDER_TYPE_CASH);
gpTenderTypes.add(new Card1(), DBConstants.TENDER_TYPE_CREDIT_CARD);
gpTenderTypes 添加在另一个中gridPanel gp2row 以及其他 2 个 gp2row
gp2row.addFilledComponent(gpCustDet, 1, 1, 6, 1,GridBagConstraints.BOTH);
gp2row.addFilledComponent(gpTT, 1, 7, 1, 1, GridBagConstraints.BOTH);
gp2row.addFilledComponent(gpButtonsPanel, 1, 8, 6, 1,GridBagConstraints.BOTH);
被添加到屏幕中:
this.addFilledComponent(gp2row, 2, 1, 14, 1, GridBagConstraints.BOTH);
我意识到,无论使用 setSize 或更改其大小,CardLayout 的大小都保持不变。更改其他 GridPanel(gpCustDet、gpButtonsPanel)的尺寸也没有用。
我该如何解决这个问题? 谢谢你!
I am unable to align the gridpanels in Swing because of fixed size of CardLayout.
I have a gridPanel gpTenderTypes for which i have used the Card Layout.
gpTenderTypes.setLayout(new CardLayout());
When a button is clicked, the card will change and the class will be called (for example, when creditcard button is clicked, creditcard card in the grid panel will be shown and the Card1() object will be called.
gpTenderTypes.add(new Cash1(), DBConstants.TENDER_TYPE_CASH);
gpTenderTypes.add(new Card1(), DBConstants.TENDER_TYPE_CREDIT_CARD);
gpTenderTypes is added in another gridPanel gp2row along with 2 other gridpanels.
gp2row.addFilledComponent(gpCustDet, 1, 1, 6, 1,GridBagConstraints.BOTH);
gp2row.addFilledComponent(gpTT, 1, 7, 1, 1, GridBagConstraints.BOTH);
gp2row.addFilledComponent(gpButtonsPanel, 1, 8, 6, 1,GridBagConstraints.BOTH);
gp2row is added in the screen:
this.addFilledComponent(gp2row, 2, 1, 14, 1, GridBagConstraints.BOTH);
I've realized that the size of the CardLayout remains constant irrespective of changing its size using setSize or setPreferredSize. Changing the dimensions of the other GridPanels (gpCustDet, gpButtonsPanel) is of no use either.
How do i do fix this?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CardLayout
的大小(实际上是布局为CardLayout
的组件的大小)不是由您对该组件的子组件执行的任何操作定义的,而是由组件本身及其父组件及其父组件的布局管理器。如果您的代码中没有更多详细信息,我们无法确定,但我会先查看那里。The size of the
CardLayout
(really the size of the Component whose layout is theCardLayout
) is not defined by anything you do to the children of that component, but rather by the component itself and its parent component and its parent's layout manager. Without some more detail in your code we can't be sure but I would look there first.