Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #260
| From | "MrFred" <mrfred@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Problem Setting Column Wi |
| Message-ID | <1164846406.486222.197610@l12g2000cwl.googlegroups.com> (permalink) |
| Newsgroups | comp.lang.java.gui |
| Date | 2011-04-27 15:26 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
Hi All,
I'm attempting to set the width of some columns in a JTable to the size
of their column header's plus the column margin.
I call the following method for each column in the table. I don't want
some columns to have a fixed size hence the boolean.
private void setColumnWidth(JTable jTableIn, int intIn, boolean
booleanIn)
{
String value = jTableIn.getColumnName(intIn);
JTableHeader jHeader = jTableIn.getTableHeader();
FontMetrics metrics =
jTableIn.getGraphics().getFontMetrics(jHeader.getFont());
int width = metrics.stringWidth(value) + (2 *
jHeader.getColumnModel().getColumnMargin());
if (booleanIn)
{
jTableIn.getColumnModel().getColumn(intIn).setMaxWidth(width);
jTableIn.getColumnModel().getColumn(intIn).setMinWidth(width);
}
jTableIn.getColumnModel().getColumn(intIn).setPreferredWidth(width);
}
The problem is that the text in the headers in always truncated, which
is not what I expect. Any suggestions as to how I can do this better.
Thanks,
MrFred.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.gui | Previous | Next — Next in thread | Find similar
Problem Setting Column Wi "MrFred" <mrfred@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000 Re: Problem Setting Colum "hiwa" <hiwa@THRWHITE.remove-dii-this> - 2011-04-27 15:26 +0000
csiph-web