Solved

swing application

Posted on 2002-06-28
5
174 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 99
micro services vs rest web services 16 107
throw exception 21 44
maven module vs maven project 3 24
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

832 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