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.  
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

751 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