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
  • 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.  
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now