[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

browser

Posted on 2004-10-26
54
Medium Priority
?
507 Views
Last Modified: 2010-07-27
any guidance to pop up a web browser when i click a hyperlink at JEditorPane?

Hope to get expert help..thanks..
0
Comment
Question by:tloip
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 20
  • 17
  • 15
  • +1
54 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 12411876
http://javaalmanac.com/egs/javax.swing.event/Hyperlink.html

That won't pop up browser though

Hmmm...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12411877
Runtime.getRuntime().exec("start " + link.getURL().toString());
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12411890
(where 'link' is really the event)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 35

Expert Comment

by:TimYates
ID: 12411902
>  (where 'link' is really the event)

And you are on Windows ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12412004
>>And you are on Windows ;-)

Yes. (The probability is high ;-))
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12412025
> Yes. (The probability is high ;-))

True, but you'll make us poor Linux users cry ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12412092
Producing a single solution across Windoze versions is hard enough, let alone cross-platform

>>us poor Linux users

What are you running?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12412252
I'm at work, so it's RedHat linux of some variety (probably Enterprise)...

I've got Windows at home though ;-)  I was just being cheeky ;-) hehehe
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12412322
uname -a

;-)
0
 

Author Comment

by:tloip
ID: 12412942
Oh, currently my program using the code that almost same as in this link
http://javaalmanac.com/egs/javax.swing.event/Hyperlink.html
but i want to work it to pop up browser.

I would like to ask, following code used to pop up web browser?
Runtime.getRuntime().exec("start " + link.getURL().toString());

If yes so, is it possible for me to place within "try" part??
   
    class MyHyperlinkListener implements HyperlinkListener {
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                JEditorPane pane = (JEditorPane)evt.getSource();
                try {
                    // Show the new page in the editor pane.
                    pane.setPage(evt.getURL());
      >>>>  Runtime.getRuntime().exec("start " + link.getURL().toString());
                } catch (IOException e) {
                }
            }
        }
    }
0
 

Author Comment

by:tloip
ID: 12413011
opss..i'm so confuse with the comment about you people discussing about either using window or linux. haha..

after i go through this link,
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21138518.html

I'm trying to guess that it is different to pop up a browser when running under window or linux. Is that right? Or there is other meaning??  
0
 

Author Comment

by:tloip
ID: 12413041
For me, i need to run this at both platform. Thus, is it i need to follow the guidance in this follwing link:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21138518.

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12413335
>>If yes so, is it possible for me to place within "try" part??

Yes, just do

Runtime.getRuntime().exec("start " + evt.getURL().toString());

Linux itself is not a homogeneous platform. There is no certaintly what browser is going to be installed

   
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 120 total points
ID: 12413402
>>There is no certaintly what browser is going to be installed

=

There is no certainty as to what browser is going to be installed. You can end up writing *a lot* of code and still not have this bulletproof. A useful start may be the following:

String command = null;
String url = evt.getURL().toString();
if (File.separatorChar == '/') {
  command = "/usr/bin/netscape ";
}
else {
  command = "start ";
}
Runtime.getRuntime().exec(command + url);
0
 

Author Comment

by:tloip
ID: 12419058
Alright, i understand your explanation. Thanks.
0
 

Author Comment

by:tloip
ID: 12419108

(running in window) when i clicked the link in the JEditorPane, it doesn't pop up a browser  but error occured. What is the matter? Am i placing the code in wrong place?


                try {
          String command = null;
       String url = e.getURL().toString();
        if(File.separatorChar == '/'){
        command ="/usr/bin/netscape";
        }else{
        command = "start";
        }
        Runtime.getRuntime().exec(command + url);
                }
                catch (Exception ev){
                      ev.printStackTrace();
       
                }
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12419114
you're probably missing a space:

 Runtime.getRuntime().exec(command + " " + url);
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12419118
Also, you might want to add a properties file to your application, so Linux users can set the location of their browser of choice...  :-)
0
 

Author Comment

by:tloip
ID: 12419480
>> add a properties file

For my case, the url doesn't fixed because my program allow client
to create a hyperlink by using html code their own.For example, client type:

<a href="http://www.yahoo.com">GO</a>

Then, a link, GO, created in JEditorPane.
When the link clicked, yahoo page will displayed on a pop up browser.

0
 

Author Comment

by:tloip
ID: 12419491
I have added space on it but result still the same.
This my actual code. Am i placing the correct place???

    public void hyperlinkUpdate(HyperlinkEvent e) {
        if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            sourcePane = (JEditorPane) e.getSource();
      if (e instanceof HTMLFrameHyperlinkEvent) {
                HTMLFrameHyperlinkEvent event = (HTMLFrameHyperlinkEvent) e;
      System.out.println(event.getTarget());
               HTMLDocument doc = (HTMLDocument) sourcePane.getDocument();
      doc.processHTMLFrameHyperlinkEvent(event);
      }
            else {
                try {
          String command = null;
       String url = e.getURL().toString();
        if(File.separatorChar == '/'){
        command ="/usr/bin/netscape";
        }else{
        command = "start";
        }
        Runtime.getRuntime().exec(command + " " + url);
                }
                catch (Exception ev){
                      ev.printStackTrace();
       
                }
                  }
            }
      }
      
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12419596
Change

       Runtime.getRuntime().exec(command + " " + url);
 
to

       String cmd = command + " " + url ;
       System.out.println( "Executing '" + cmd + "'" ) ;
       Runtime.getRuntime().exec( cmd );
 
what does it print out?

> For my case, the url doesn't fixed because my program allow client
> to create a hyperlink by using html code their own.For example, client type:

Yeah, I meant a properties file to define the:

       command ="/usr/bin/netscape";

bit ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12420138
Look at the difference between my code and yours (in that order)

>>command = "start ";

>>command = "start";

You can also try

command = "C:/Program Files/Internet Explorer/IExplore.exe ";
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12421500
Just found this:

http://browserlauncher.sourceforge.net/

Which looks quite cool :-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12421561
Yes. Kinda knew about that, but didn't mention it as it seems a bit over the top. Still, may be worth looking at
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12421751
It's just one class...and it seems to work on Linux (well, it launches netscape, which isn't my main browser I use -- FireFox -- but at least it's a browser) ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12421894
>>and it seems to work on Linux

I wonder if it just does the same as my naive code example? ;-)
0
 
LVL 35

Accepted Solution

by:
TimYates earned 120 total points
ID: 12421988
Basically, yes...  But there's LOADS of code for handling Macs in there...  

And the windows call seems to run:

    cmd.exe /c start "" "http://www.yoururl.com"

on Windows NT, and

    cmd.exe /c start "http://www.yoururl.com"

without the "" parameter for Win 98/95 :-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12422017
Oh yes, was thinking start may only be a command interpreter command (blush ;-))
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12422045
:-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12422058
Personally, if you want a short version, my second Windows suggestion (iexplore) should work on < NT (i.e. 98, 95) as well.

cmd.exe /c start "" "http://www.yoururl.com"

definitely won't, but i guess the launcher boys have coded for < NT somewhere
0
 

Author Comment

by:tloip
ID: 12424262
>> command = "C:/Program Files/Internet Explorer/IExplore.exe ";
After i placed this at my try part, it able to pop up a browser and able to display the page i want.

but..

I was wondering, how if IExplore.exe not detected at C drive at another PC?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12424268
use that library, or the "cmd.exe /c" command above..
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12424277
you missed out on 4 hours of us chatting about this ;-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12424378
>>I was wondering, how if IExplore.exe not detected at C drive at another PC?

Well you've hit on another problem. The registry would possibly have to be read for this whole thing to be solid. I must say though - how likely is it that it won't be installed on that drive, especially (and M$ loves to claim this) since it's pretty much integrated into the OS?
0
 

Author Comment

by:tloip
ID: 12424382

Oh yea, missed out...since my connection got probelm..
0
 

Author Comment

by:tloip
ID: 12424394
wana catch  up now..:)
0
 

Author Comment

by:tloip
ID: 12424463
you means using this

>>cmd.exe /c start "" "http://www.yoururl.com"

how to use this?

0
 

Author Comment

by:tloip
ID: 12424484
Oh..i got it!!!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12424493
Change the earlier

>>command = "start ";

to

>>command = "cmd.exe /C start ";

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12424502
As i mentioned, that will fail on < Win NT
0
 

Author Comment

by:tloip
ID: 12424583
great!

>>As i mentioned, that will fail on < Win NT
em...alright. I think my program might only be used in window XP/98 and Linux.
Thus, should be no problem


this code being called for Linux OS??
 command ="/usr/bin/netscape";

Do i need to do same like " cmd.exe "  for linux ?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12424604
>>Thus, should be no problem

start will fail on Win 98

>>Do i need to do same like " cmd.exe "  for linux ?

No
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12424651
>>start will fail on Win 98

To be more precise, it's the combination of start and cmd.exe that will fail. I would recommend iexplore, and also testing the launcher program if you have difficulties
0
 

Author Comment

by:tloip
ID: 12424775
>> start will fail on Win 98
main platform will be used is Linux. I might mention my program about start will fail on win98.

>>I would recommend iexplore, and also testing the launcher program if you have difficulties
Anyway, thanks for your recommend, i got it.

Thanks for such a long long guidance!
This is the best and clear guidance and fastest reply i ever received.
Fantastic and excellent !!

Your guidance is highly appreciated. Again, thanks! :-)

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12424822
8-)

Thanks, but i'd be happier if you gave Tim Yates some points too. He *did* mention my blunder over cmd.exe for one thing. I'll get the question reopened - you don't need to do anything for now.
0
 
LVL 20

Expert Comment

by:Venabili
ID: 12424980
Question reopened per request from the awarded expert

Venabili
Java Page Editor
0
 

Author Comment

by:tloip
ID: 12424982
Frankly...you both are friendly and good guidance expert!
Yea..i was wondering to give Tim Yates..but just not i clicked the "comment" too fast.
I don't notice with the Split point..since i never did this before.
Actually i just started often using EE recently even registered earlier. Thus, not so familiar with giving points, whatelse split point. haha..
Is it possible to give point to T Y since i have given to you?


0
 

Author Comment

by:tloip
ID: 12425004
>> Question reopened per request from the awarded expert

What is the purpose of using it?
0
 
LVL 20

Expert Comment

by:Venabili
ID: 12425024
Now you can make the split.

Venabili
0
 

Author Comment

by:tloip
ID: 12425060
Oh...thanks!!!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12425272
;-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12431070
:-)  Glad you got it sorted :-)

And thanks CEHJ :-D  *bow*
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12432545
;-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question