java 如何使用 Netbean 的 GUI Builder 单独调整表列的大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4980691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I resize table columns individually using Netbean's GUI Builder?
提问by akbiggs
In making a quick mockup of a project's end design using Netbeans' GUI Builder, I've run into a problem with the options given to me for the Table object. It seems that I can't resize columns individually, only the whole table. Am I wrong, and is there a way to resize columns using the GUI Builder? If not, could I accomplish this using Swing code? How?
在使用 Netbeans 的 GUI Builder 制作项目最终设计的快速模型时,我遇到了为 Table 对象提供的选项的问题。似乎我不能单独调整列的大小,只能调整整个表格。我错了,有没有办法使用 GUI Builder 调整列的大小?如果没有,我可以使用 Swing 代码完成此操作吗?如何?
回答by gigadot
SInce the default JColumnModel
created by Netbeans GUI builder is hidden and cannot be customized in Properties plalette, you will have to do it programatically.
JColumnModel
由于 Netbeans GUI builder 创建的默认设置是隐藏的,并且无法在 Properties 面板中进行自定义,因此您必须以编程方式进行。
Go the `Source view' (there is a small button above the editor pane to switch between Source View and Design View) and put the following code in the constructor
转到“源视图”(编辑器窗格上方有一个小按钮可以在源视图和设计视图之间切换)并将以下代码放入构造函数中
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
// Insert this line into your code
jTable1.getColumnModel().getColumn(0).setPreferredWidth(20);
}
Fore more details, read hereor google for "jtable set column size".
有关更多详细信息,请阅读此处或谷歌“jtable 设置列大小”。
Hereis another useful information.
这是另一个有用的信息。
回答by RaKXeR
For anyone still looking for the answer that finds this post, the selected answer is not the correct way to do it from the Netbeans GUI.
对于仍在寻找找到这篇文章的答案的任何人来说,选定的答案不是从 Netbeans GUI 执行此操作的正确方法。
As said in one of the answers here(by Heater Buch), in order to change the column width:
正如此处的其中一个答案(由 Heater Buch 提供)所述,为了更改列宽:
- In design view, right-click over the table;
- Choose "Table Contents ..." and a Customizer Dialog will appear.
- Click the "Columns" tab, and there you will be able to set several properties, including the preferred / minimum / maximum width.
- 在设计视图中,右键单击表格;
- 选择“表格内容...”,将出现一个定制器对话框。
- 单击“列”选项卡,您将能够在其中设置多个属性,包括首选/最小/最大宽度。