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

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

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

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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

719 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