问题描述
我们有一个JPanel至极包含多个JPanels至极含有JComponent上(假设的JLabel和JTextboxes)
We have a JPanel wich contains multiple JPanels wich contain JComponents (let's say JLabels and JTextboxes)
在每个内部JPanels的,我们使用的JGoodies布局,以确保所有标签的正确alignement
Inside each of the internal JPanels we use JGoodies Layout in order to ensure proper alignement of all Labels.
不过,当然,我们希望把所有的它们是独立的子面板对齐的标签。
But of course we would like to have all the Labels aligned independently on which subpanel they are.
我们怎么能做到这一点,没有固定包含的JLabel列的宽度?
How could we do that, without fixing the width of the column which contains the JLabels?
我们不能松JPanels因为我们有大约组件组国界
We can't loose the JPanels since we have to have Borders around groups of Components
推荐答案
仅仅因为的JPanel
活动的边界,并不意味着他们实际上需要包含它们的表观内容。设置面板为透明。添加面板和部件,以封闭面板。加入垫片组件以模仿在布局面板的边框。您还需要关掉优化图,或者类似的,重叠的部分。
Just because the JPanel
s have borders, doesn't mean that they actually need to contain their apparent contents. Set the panels to transparent. Add the panels and the components to the enclosing panel. Add spacer components to mimic the insets of the panels in the layout. You will also need to switch off "optimised drawing", or some such, for overlapping components.
这篇关于跨对齐面板Swing组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!