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 / March 2004

Tip: Looking for answers? Try searching our database.

Setting jtable cell height same as jtextfield height?

Thread view: 
Ding - 17 Mar 2004 21:02 GMT
Hello,

I'm trying to use my own StandardOneClickEditor which extends
DefaultCellEditor as a cell editor in a jtable.

====
public class StandardOneClickEditor
     extends DefaultCellEditor{
   public StandardOneClickEditor(){
     super(new JTextField());
     this.setClickCountToStart(1);
   }
 }
====

StandardOneClickEditor uses a JTextField as the editor component. When
i run the program and click on the cell the StandardOneClickEditor
appears with the jtextfield. No problem here.

But it seems that the cell height is a little to small for a
jtextfield with border. So i made a little function which makes all
cells in a jtable the same height as a standard jtextfield:

====
public FieldTable() {
   super();
    this.setRowHeight((int)new
JTextField().getPreferredSize().getHeight());
}
====

This seems like a nice working hack, but i'm wondering if this is the
right thing to do. Any ideas about this?

Regards,
Rob Jones - 18 Mar 2004 12:02 GMT
> But it seems that the cell height is a little to small for a
> jtextfield with border.
JTable has a default row height of 16 pixels.
The brain dead part is that you have to adjust this by hand
using setRowHeight. If you use a different font or put a
custom component in the table the table does not get the
preferred size from the contents.
See
http://www.chka.de/swing/table/cell-sizes.html

> So i made a little function which makes all
> cells in a jtable the same height as a standard jtextfield:
[quoted text clipped - 9 lines]
> This seems like a nice working hack, but i'm wondering if this is the
> right thing to do. Any ideas about this?

Seems resonable. It works.
You might want to put a sanity check in case some other JVMs/JREs dont
work the same. (Possible that empty textField might have default 0s).
eg (untested code)
public FieldTable()
{
    super()
    int rowHeight = (int)new JTextField().getPreferredSize().getHeight();
    if (rowHeight >= 1) this.setRowHeight(rowHeight);
}
Ding - 19 Mar 2004 16:15 GMT
>> But it seems that the cell height is a little to small for a
>> jtextfield with border.
[quoted text clipped - 5 lines]
>See
>http://www.chka.de/swing/table/cell-sizes.html

Thats a handy link, thanks.

>> So i made a little function which makes all
>> cells in a jtable the same height as a standard jtextfield:
[quoted text clipped - 20 lines]
>     if (rowHeight >= 1) this.setRowHeight(rowHeight);
>}

Thanks, it's good to do it at the save way :)
Ding - 19 Mar 2004 16:19 GMT
>>> But it seems that the cell height is a little to small for a
>>> jtextfield with border.
[quoted text clipped - 7 lines]
>
>Thats a handy link, thanks.

After browsing a little more at the given link i've come to the
conclusion that it really is a nice site. I'm wondering why google
didnt gave me that site. It's now on my desktop :-)


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.