Getting right end of text displayed in cells of a JTable column

Hey All,

Platform: WinXP, Java 5.0.

I have a simple one-column table whose cells contain pathnames of user-selected files. The pathnames may be quite long, and when they're too long for the fixed width of the column (the containing JFrame is not resizable), I want the trailing (right) end of the pathnames to visible (so the filenames are visible) and for elipsis to be used on the left side (omitting root directory, etc., if need be). I can't figure out how to do this. I've tried many different approaches. Currently I use a class that extends TableCellRenderer, but no combination of alignment settings in this class seems to do the trick.

I've noticed that in the case of JTextFields, this manner of display seems to be the default, no matter what alignment setting I choose. I can't seem to get the desired effect with the display of cells in my JTable though.

Anyone have any suggestions?

Thanks in advance.

[957 byte] By [anamaekaa] at [2007-11-27 1:41:01]
# 1

Hey

Here are some links that maybe can be helpfully:

http://forum.java.sun.com/thread.jspa?threadID=769302&messageID=4384459

http://www.velocityreviews.com/forums/t141275-right-align-cell-values-in-jtable-.html

http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=2&t=006900

http://www-128.ibm.com/developerworks/library/j-jtable/

Satanduvel

Satanduvela at 2007-7-12 0:55:56 > top of Java-index,Desktop,Core GUI APIs...
# 2
Check out this custom renderer: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=634798
camickra at 2007-7-12 0:55:56 > top of Java-index,Desktop,Core GUI APIs...
# 3
After you implement the above suggestions, it may also be pretty slick to add this project to your code:https://datatips.dev.java.net/So the left end will pop open on mouseover
pthorsona at 2007-7-12 0:55:56 > top of Java-index,Desktop,Core GUI APIs...
# 4
If it works pls give starsSatanduvel
Satanduvela at 2007-7-12 0:55:56 > top of Java-index,Desktop,Core GUI APIs...
# 5

Great job camickr,

That did just what I wanted; you get the points for sure! I will say that It's surprising to me that Swing leaves so much work in calculation to be done for this simple idea.

Btw, I also want to mention here that there's another forum issue I raised and you responded to recently, and you never quite answered my question there:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=5160875

That's got 10 pts riding on it too, if you care to revisit the issue...

Thanks very much for the good work on the CellRenderer.

anamaekaa at 2007-7-12 0:55:56 > top of Java-index,Desktop,Core GUI APIs...
# 6

Satanduvel, thanks for your time & input,

Your links were useful for explaining how to set alignment in a custom CellRenderer, but the problem I described isn't solved by setting alignment in the CellRenderer. To see what does the trick, check out camickr's solution for which he recieved all 10 dukes stars.

anamaekaa at 2007-7-12 0:55:56 > top of Java-index,Desktop,Core GUI APIs...
# 7
pthorson,That looks like a REALLY slick addition. I'm going to give it a try as soon as I get a chance.Thanks!
anamaekaa at 2007-7-12 0:55:56 > top of Java-index,Desktop,Core GUI APIs...