Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I control the size of my JTable column widths?

column CONTROL jtable size widths
0
Posted

How do I control the size of my JTable column widths?

0

JTable contains clever (perhaps too clever) logic for allocating column widths when the overall JTable size changes. To explicitly control the size of your individual JTable columns, it is highly advised that you first call table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); Then you will be able to control the size of JTable columns by calling table.getColumnModel().getColumn(n).setPreferredWidth(numPixels); for each column in your table. See J2PrinterWorksTestApplication.java for examples. Also, if you have a JTable much larger than a page width and use SHRINK_TO_FIT scaling to fit to one page , you may find that the default font size to be way too small once scaled down. The easiest way to address this problem is to adjust the sizes of your JTable columns in advance so that the overall JTable size more nearly approximates the printed page. Alternatively, you can increase your font sizes so that they are more in proportion to your JTable size.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123