File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Format to display Filepath in JTextArea/JTextField/ JLabel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Format to display Filepath in JTextArea/JTextField/ JLabel" Watch "Format to display Filepath in JTextArea/JTextField/ JLabel" New topic
Author

Format to display Filepath in JTextArea/JTextField/ JLabel

Anuj Joshi
Greenhorn

Joined: Feb 05, 2009
Posts: 22
I want to display a file path in JTextarea/ JLabel.

I want to display it in following format , "C:/Program Files/... .../abc.xml"
means if file path i too long then i want to display it by above format starting with left & ends at right & middle part can be shown in dots.

so how can I show this format in JTextArea/ JTextFiled/ JLabel.
which alignment should i use for this.

Please help me...

Thanks
Sharda
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

First off, you need to firm up those specifications.

1. What constitutes the 'right part' (the last slash and everything that follows it? a fixed number of characters?)
2. What constitutes the 'left part' (as many characters as can be accommodated? up to the last slash that can be accommodated?)
3. Depending on the first two specs, what's the fallback if the 'right part' and 'left part' together are too long to display?
4. In the event that dots are required, what's the minimum (and maybe maximum) number of dots? how are they to be grouped?
5. Does the solution have to cater to resizing of the Swing component used for display? With changing the LaF? With setting a different Font?

Whatever the spec, you'll want to look into java.awt.font.TextLayout and its getBounds() method.

Oh, and does this have anything at all to do with JSP (Java Server Pages)? Looks to me it would sit better in the GUI forum.

luck, db
There are no new questions, but there may be new answers.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60740
    
  65

Not a JSP question. Moved to the Swing forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Anuj Joshi
Greenhorn

Joined: Feb 05, 2009
Posts: 22
hey thanks
 
wood burning stoves
 
subject: Format to display Filepath in JTextArea/JTextField/ JLabel
 
Similar Threads
J2ME
Suggestion
mutilple color text in Jtextarea or JTextPane
Line brake in JLabel?
Please help with JTextArea problem...