Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2006

Tip: Looking for answers? Try searching our database.

Problem Setting Column Widths

Thread view: 
MrFred - 30 Nov 2006 00:26 GMT
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.
hiwa - 30 Nov 2006 02:54 GMT
> Hi All,
>
[quoted text clipped - 29 lines]
>
> MrFred.
This thread may help:
http://forum.java.sun.com/thread.jspa?threadID=701058


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.