Solved

Need Wrapping text and an image in a JDialog for an About Box in a Java Swing GUI

Posted on 2006-11-20
7
295 Views
Last Modified: 2010-03-31
I need wrapping text and an image in a JDialog for an About Box in a Java Swing GUI.  Should I be using a JDialog, JWindow, JOptionPane or something else?  I tried JWindow but I could not move the dialog.  Should I use a JTextArea for the wrapping text?  How do I get an image on the dialog.  

Thanks,
Dave
0
Comment
Question by:gdkinney_2
[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
  • 5
  • 2
7 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 17980151
For an aboutbox you can use JWindow if you want to give it your private skin,
otherwise a JDialog is simpler.
Put your text and pictures as an HTML page into a JTextArea on the aboutbox.
;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17980179
You can test the text of your HTML in any browser before you put it into the JTextArea.
Don't use JOptionPane: you can't customise it.
You could not move JWindow: correct, it has no title bar: aboutboxes are not moved, only OK-ed.
;JOOP!
0
 

Author Comment

by:gdkinney_2
ID: 17980820
I can test the text of a JTextArea in a browser?  So I can use <HTML> tags like <BR> in the text of a JTextArea?  This is the About box for a Java Swing Application it does not run in a browser.  
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Expert Comment

by:sciuriware
ID: 17981764
On second thoughts, in your case a JEditorPane is stronger for HTML content than an ordinary JTextArea:

Create the text in an editor, save it as .htm, test it in FireFox or Internet Explorer,
then paste the text into:
    String content = "<paste here>";
// and:
    JEditorPane ep = new JEditorPane();
      ep.setEditable(false);
      ep.setEditorKit(new HTMLEditorKit());
      ep.setText(content);

put 'ep' in a Frame and display it.
   
You can apply HTML in almost any control, but JEditorPane is almost as powerful as a browser without plug-ins.

;JOOP!
0
 

Author Comment

by:gdkinney_2
ID: 17983313
Sciuriware,
    I took your advive and used a JEditorPane and wrote some HTML code to get the content I wanted in my dialog.  I tried to add a image tag:
<IMG SRC='mygif.gif'> into the content.  I just had the gif file name for the src attribute because the gif is in the same directory (folder).  For some reason when I run the application and look at the dialog the gif file does not render in the About dialog.  The code in the content string is OK because I can save the content string as a html file and bring it up in a browser and the gif renders fine.  So for some reason maybe the HTMLEditorKit class is having trouble rendering the image.

Dave
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 500 total points
ID: 17983591
You need a trick for images:

this is how I did it:

      ep.setText("<IMG SRC=\""  + getLocalURL("Icon.gif").toString() + "\">");

where:

       URL getLocalURL(String fileName)
       {
             return(this.getClass().getResource(fileName));
       }

// This code loads an icon that is in the same directory as the class file of this object.
// All pathnames you can give will be relative to the class file,
// so it keeps working when you create .jar with all files in it.


;JOOP!


0
 
LVL 24

Expert Comment

by:sciuriware
ID: 17993633
:)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.

740 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