Solved

swing application

Posted on 2002-06-28
5
175 Views
Last Modified: 2010-03-31


I am writting an swing application.
After querying from db, I have to display the result in the following format:

Field 1  Field2  Field3
xxx      yyyy    zzz
aaa      bbbb    c
ddd      ff      gg

...


Do i need to use JTable?
if so, how to use JTable?
0
Comment
Question by:stanleyhuen
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 7115860
you can display it as HTML - use JEditorPane with content type "text/html":

      StringBuffer buff = new StringBuffer();
      buff.append("<Table>");
      buff.append("<TR>");
      buff.append("<TD>");
      buff.append("Field 1");
      buff.append("</TD>");
      buff.append("<TD>");
      buff.append("Field 2");
      buff.append("</TD>");
      buff.append("<TD>");
      buff.append("Field 3");
      buff.append("</TD>");
      buff.append("</TR>");

      buff.append("<TR>");
      buff.append("<TD>");
      buff.append("xxx");
      buff.append("</TD>");
      buff.append("<TD>");
      buff.append("yyy");
      buff.append("</TD>");
      buff.append("<TD>");
      buff.append("zzz");
      buff.append("</TD>");
      buff.append("</TR>");

      buff.append("<TR>");
      buff.append("<TD>");
      buff.append("aaa");
      buff.append("</TD>");
      buff.append("<TD>");
      buff.append("bbbb");
      buff.append("</TD>");
      buff.append("<TD>");
      buff.append("c");
      buff.append("</TD>");
      buff.append("</TR>");

      buff.append("<TR>");
      buff.append("<TD>");
      buff.append("ddd");
      buff.append("</TD>");
      buff.append("<TD>");
      buff.append("ff");
      buff.append("</TD>");
      buff.append("<TD>");
      buff.append("gg");
      buff.append("</TD>");
      buff.append("</TR>");

      buff.append("</Table>");
      jEditorPane1.setContentType("text/html");
      jEditorPane1.setText(buff.toString());
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 7115875
Use a JTable
Heres an example:

Object[] columns = { "Field1", "Field2", "Field3" };
Object[][] data = {
  { "xxx", "yyy", "zzz" },
  { "aaa", "bbbb", "c" },
  { "ddd", "ff", "gg"}};

JTable table = new JTable(data, columns);
frame.getContentPane().add(new JScrollPane(table));
0
 
LVL 9

Expert Comment

by:Ovi
ID: 7115888
Just look in the api help at the JTable constructors :

JTable(Object[][], Object[])
and
JTable(Vector, Vector)
0
 
LVL 9

Expert Comment

by:Ovi
ID: 7115890
I believe the second constructor is more realiable for you since the size of a Vector can grow dinamically, while of an array not (you don't know exactly in a resultSet the number of rows/columns)
0
 
LVL 92

Expert Comment

by:objects
ID: 7131588
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

828 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