This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Javascript in JEditorPane - Best practises? 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 "Javascript in JEditorPane - Best practises?" Watch "Javascript in JEditorPane - Best practises?" New topic
Author

Javascript in JEditorPane - Best practises?

Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
Hi there

I would like to get some opions on the best practises for what I would like to acheive.

I have A JEditorPane that shows a HTML page. On this HTML page are check boxes that the user interacts with. On the click of a button on the HTML page, I need to write the user's selection to a file. (I don't want to use an Applet!)

To acheive this I have found a few ways that I could do it.

1) Use Javascript to call a Java function that resides in the same place that loads the HTML page (ie a class in my application.)
2) Use javascript to call a java function that is in the html page.

I thought about doing it all in Javascript but apparently you can't write files unless the applet is signed and I'm not using an applet.

Kind regards,
Rachel
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Question: where are you getting the interpretor for the JavaScript from? Are you writing it too? JavaScript isn't part of HTML, so the HTMLEditorKit will just see it as plain text. Sounds like what you are writing is a browser, which is a big, complex job. If that's true, what do you hope to gain from not using IE/Mozilla/Opera etc.?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
I can't actually believe that I overlooked that the pane wont interpret Javascript!

Just to elaborate on what I'm doing because I'm not doing a browser (thank goodness!)

I'm writing a communications application. It has email, weather and news and gets the information on demand from a central server.

The original application was written in VisualBasic and I'm trying to hold as much of the old look in the new application. And one of these items is this News section, and more specifically the registration page. (So that's why I'm not using IE or the likes.)

Now, the news section is made up of HTML pages. So on the news tab (it's designed on a tabbed pane) I have a menu on the left and the content on the right. For the registration part of the News, I need the user to click on a checkbox if he wants to receive that item of news. Then the user pushes a button and the file is saved so that it can be sent back to the server later on.

That's what I'd like to do as it is what the origianl application does. If it's not possible, then I'll just have to change it.

Thanks,
Rachel
[ August 10, 2004: Message edited by: Rachel Swailes ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Sounds difficult without actually writing a browser. I'll bet your original VB app was using IE in the background to do this too. What you could do is embed Gecko into your app. I hear its not too difficult - but then I've never done it myself.
Rachel Swailes
Ranch Hand

Joined: May 18, 2004
Posts: 434
Thanks Paul.

I'll give it a bash and see how it goes.

Thanks again!
Rachel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Javascript in JEditorPane - Best practises?
 
Similar Threads
need help
passing a parameter back to my HTML page from my applet
getting user input
Printing HTML With Java
Instance of a browser