Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Format to display Filepath in JTextArea/JTextField/ JLabel

 
Anuj Joshi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a JSP question. Moved to the Swing forum.
 
Anuj Joshi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic