Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HTML in JEditorPane  RSS feed

 
radu enea
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to make a mini web browser for a project. I load the html in a JEditorPane by specifying the url of that page. My problem now is that I have to give the user of my browser the possibility to save pictures. For this I need access to the HTML code of that page. How can I access that code? I need it for parsing and for extracting the URLs of images contained in that web page. I saw that JEditorPane has a method getStream() that I thought I could use to fetch a stream of data but it didn't work out. Is there any possibility to get that html in a string or in a stream without performing http requests? ...If not can u give me some point where to start from? because i have no idea of how to do this.
 
radu enea
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think some code could be useful for you to understant what I meant earlier.



...and this is the code I execute when pressing the go button of my browser
 
radu enea
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it. I tried for 2 days to find the answer and it was right near me. I still have a question: as I am quite new to GUI designing in java, do you think it would be possible to recognize if a click was performed on a picture or on text? (considering the fact that I am displaing a html document in a JEditorPane)

Please let me know if you now how to do that... or if it's possible... I am using JDK 1.5 and I'm not allowed to use anything else.

Thank you!
 
Campbell Ritchie
Sheriff
Posts: 55292
156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Difficult to be sure exactly what you mean about clicks, but it would be possible to add a MouseListener to most components. Then you can have event handling when somebody clicks on a particular component.

I don't know how to distinguish between clicking on parts of a component.

Remember that if you change a component from text to picture and back, you can change the Listeners.

Look in the API specification, then INDEX, then A for addActionListener, addMouseListener, and take it from there.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!