如何给面板内的列提供固定的列宽? [英] How to give columns inside a panel fixed column widths?

查看:54
本文介绍了如何给面板内的列提供固定的列宽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我要在面板内设置一组固定列跨度的列,那是最好的Swing布局?

What's the best Swing layout if I want to have a set of columns with fixed column span inside a panel?

类似以下内容:

我希望第一列跨越面板宽度的20%,第二列跨越面板宽度的50%,第三列跨越面板宽度的30%

I would like the first column to span 20% of the width of the panel, the second column to span 50% of the panel and the third column to span 30% of the width of the panel

推荐答案

对于您的情况, GridBagLayout 是您的最佳选择,即使它是最复杂的.您还可以采用其他布局,尽管这取决于您实际尝试执行的操作.您可以查看 GridLayout BoxLayout ,

For your case, GridBagLayout would be your best option even though it's the most complex. There are other layouts that you could get away with although it depends on what you are actually trying to do. You can look at the GridLayout, the BoxLayout, the BorderLayout and even the default layout (FlowLayout) could work.

您还可以看一下JTable,因为您撰写了有关列的文章,而我注意到左侧的小圆圈看起来像是一个索引号或类似的东西,但我可能是错的.也许您正在尝试做一张桌子...

You could also look at JTable because you write about columns and I noticed the little circle on the left that kind of look like an index number or something, but I could be wrong. Maybe you are trying to do a sort of table...

这篇关于如何给面板内的列提供固定的列宽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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