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

Posted on 2006-11-20
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.  

Question by:gdkinney_2
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
LVL 24

Expert Comment

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.
LVL 24

Expert Comment

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.

Author Comment

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.  
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

LVL 24

Expert Comment

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.setEditorKit(new HTMLEditorKit());

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.


Author Comment

ID: 17983313
    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.

LVL 24

Accepted Solution

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() + "\">");


       URL getLocalURL(String 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.


LVL 24

Expert Comment

ID: 17993633

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

617 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