> [...]
> > all I want is very very easy:
[quoted text clipped - 9 lines]
> String s = file.toURL().toString().replace(' ', '+');
> // I get here: "file:/C:/Dokumente+und+Einstellungen/fritscht/stave.ico"
Depending on the intended use, the '+' may not work well. I think
you'll find that using toURI() works better than toURL() does. It
replaces those spaces with "%20" and will encode anything else needed.
And URI contains a toURL() method, should it be useful, but on my system
(in US English and with limited knowledge of other languages) I see no
difference in the result.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama
Thomas Fritsch - 15 Jan 2007 18:21 GMT
Steve W. Jackson schrieb:
>>File file = new File(System.getProperty("user.home"), "stave.ico");
>>String s = file.toURL().toString().replace(' ', '+');
[quoted text clipped - 3 lines]
> you'll find that using toURI() works better than toURL() does. It
> replaces those spaces with "%20"
Agreed!
My browser can display
file:/C:/Dokumente+und+Einstellungen/
but says "File not found" on
file:/C:/Dokumente%20und%20Einstellungen/
Hence, the better solution for the OP is indeed
file.toURI().toString()
> and will encode anything else needed.
Not agreed.
I checked toURI().toString(). It does not encode non-ASCII characters
(for example german umlauts):
"ü" remains "ü", instead of being translated to "%FC".
> And URI contains a toURL() method, should it be useful, but on my system
> (in US English and with limited knowledge of other languages) I see no
> difference in the result.

Signature
Thomas
Thomas Fritsch - 15 Jan 2007 18:29 GMT
Thomas Fritsch schrieb:
> Steve W. Jackson schrieb:
>
[quoted text clipped - 14 lines]
> Hence, the better solution for the OP is indeed
> file.toURI().toString()
Stupid me. I meant it this way around:
Agreed!
My browser can display
file:/C:/Dokumente%20und%20Einstellungen/
but says "File not found" on
file:/C:/Dokumente+und+Einstellungen/
Hence, the better solution for the OP is indeed
file.toURI().toString()
>> and will encode anything else needed.
>
[quoted text clipped - 6 lines]
>> system (in US English and with limited knowledge of other languages) I
>> see no difference in the result.

Signature
Thomas
phillip.s.powell@gmail.com - 16 Jan 2007 14:09 GMT
> > [...]
> > > all I want is very very easy:
[quoted text clipped - 16 lines]
> (in US English and with limited knowledge of other languages) I see no
> difference in the result.
It appears that toURL() is deprecated within java.io.File.
I tried this instead:
String s = file.toURI().toURL().toString().replace(' ', '+');
Which gave me this as a result:
Your new icon can be found <a
href="file:/C:/Documents%20and%20Settings/me/stave.ico>here</a>
That was still not clickable, however, when I tried to click onto the
"link" from within the JLabel within the JFrame.
Sorry, I thought that was it! :(
Phil
> = Steve =
Andrew Thompson - 16 Jan 2007 15:10 GMT
..
> Your new icon can be found <a
> href="file:/C:/Documents%20and%20Settings/me/stave.ico>here</a>
>
> That was still not clickable, however, when I tried to click onto the
> "link" from within the JLabel within the JFrame.
Two approaches to making a clickable link are
1) implement an HyperLinkListener in a JEditorPane
<http://java.sun.com/developer/onlineTraining/GUI/Swing1/shortcourse.html#JFCEdit
orPane>
AFAIR it can open an image directly from an HTML link.
2) add a MouseListener to the JLabel - the
changing of color for hover and active have to
be separately handled, though.
Andrew T.
phillip.s.powell@gmail.com - 16 Jan 2007 16:37 GMT
> ..
> > Your new icon can be found <a
[quoted text clipped - 7 lines]
> <http://java.sun.com/developer/onlineTraining/GUI/Swing1/shortcourse.html#JFCEdit
orPane>
> AFAIR it can open an image directly from an HTML link.
That is what I tried to do:
private JEditorPane createHyperlinkPane(String iconPathInfo) {
JEditorPane pane = new JEditorPane();
pane.setBackground(UIManager.getColor("control"));
pane.setOpaque(true);
pane.setEditorKit(new HTMLEditorKit());
pane.setFont(IconMaker.font);
pane.setText(iconPathInfo);
pane.setContentType("text/html");
pane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent evt) {
if (evt.getEventType() ==
HyperlinkEvent.EventType.ACTIVATED) {
System.out.println("you clicked!");
}
}
});
return pane;
}
private String createIconPathInfoText() {
StringBuffer sb = new StringBuffer();
sb.append("Your new icon can be found ");
try {
generateIconFilePath();
sb.append("<a href=\"" + getIconFilePath() +
"\">here</a>");
} catch (Exception e) {
sb.append("at: \"" + System.getProperty("user.home") +
File.separator +
this.getIconFileName() + "\"");
}
String iconPathInfo = sb.toString();
System.out.println(iconPathInfo);
return iconPathInfo;
}
However, the link is still not clickable in spite of the setup via
HyperlinkListener
> 2) add a MouseListener to the JLabel - the
> changing of color for hover and active have to
> be separately handled, though.
Sorry I meant JEditorPane, not JLabel
> Andrew T.
Steve W. Jackson - 16 Jan 2007 15:21 GMT
> It appears that toURL() is deprecated within java.io.File.
I still use Java 5, so I hadn't noticed that in Java 6 it is indeed
deprecated. But there's a note in the API Javadocs even in Java 5
indicating that toURL doesn't encode everything and recommending the use
of toURI, followed by the URI method toURL to accomplish the task.
> I tried this instead:
>
[quoted text clipped - 11 lines]
>
> Phil
The toString and replace parts should still not be necessary...but the
presence of the > and < parts suggest that the string in question
had angle brackets in it. Perhaps that's one part of the problem you
encountered. Plus, there's the question of a link being clickable on a
JLabel...unless it's new to Java 6 (and therefore beyond my experience),
I don't think that's possible, is it?
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama
phillip.s.powell@gmail.com - 16 Jan 2007 16:32 GMT
> > It appears that toURL() is deprecated within java.io.File.
>
[quoted text clipped - 25 lines]
> JLabel...unless it's new to Java 6 (and therefore beyond my experience),
> I don't think that's possible, is it?
I changed it to a JEditorPane, which is what I needed all along,
however, the link is still not clickable:
private JEditorPane createHyperlinkPane(String iconPathInfo) {
JEditorPane pane = new JEditorPane();
pane.setBackground(UIManager.getColor("control"));
pane.setOpaque(true);
pane.setEditorKit(new HTMLEditorKit());
pane.setFont(IconMaker.font);
pane.setText(iconPathInfo);
pane.setContentType("text/html");
pane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent evt) {
if (evt.getEventType() ==
HyperlinkEvent.EventType.ACTIVATED) {
System.out.println("you clicked!");
}
}
});
return pane;
}
private String createIconPathInfoText() {
StringBuffer sb = new StringBuffer();
sb.append("Your new icon can be found ");
try {
generateIconFilePath();
sb.append("<a href=\"" + getIconFilePath() +
"\">here</a>");
} catch (Exception e) {
sb.append("at: \"" + System.getProperty("user.home") +
File.separator +
this.getIconFileName() + "\"");
}
String iconPathInfo = sb.toString();
System.out.println(iconPathInfo);
return iconPathInfo;
}
Still have no clue what's not working.
Phil
> = Steve =
Thomas Fritsch - 16 Jan 2007 17:00 GMT
> JEditorPane pane = new JEditorPane();
> pane.setBackground(UIManager.getColor("control"));
[quoted text clipped - 12 lines]
>
> Still have no clue what's not working.
I vaguely remember that you have to do
pane.setEditable(false);
in order to get the event actually fired by the JEditorpane.
The reasoning behind that was:
When there is an editable JEditorPane, the user clicks into it because he
wants to edit the HTML text, but doesn't want to follow the clicked link.

Signature
Thomas
phillip.s.powell@gmail.com - 16 Jan 2007 17:05 GMT
> > JEditorPane pane = new JEditorPane();
> > pane.setBackground(UIManager.getColor("control"));
[quoted text clipped - 19 lines]
> When there is an editable JEditorPane, the user clicks into it because he
> wants to edit the HTML text, but doesn't want to follow the clicked link.
That was it!! Thanx!!