Solved

How to fill my jtable

Posted on 2011-09-13
3
273 Views
Last Modified: 2012-05-12
i need to fill out my jtable. how do I do that with my arraylist?

When the code below is finished I come over to a class that has a jtable named jtable1.

How do I fill this one out? I have tried diffrent solutions from the net but cant seem to get it to work.
if(comboBoxArtikel.getSelectedIndex()  == 0)
        {
            int ID = Integer.parseInt(textBox_ID.getText());
            double pris = Double.parseDouble(textBox_Pris.getText());
            Bok b1 = new Bok(ID, textBox_Namn.getText(), pris, textBox_ISBN.getText(), textField_Forfattare.getText(), textField_Genre.getText());

            label_Forfattare.setText("Författare");
            label_Genre.setText("Genre");
            label_Forfattare.setVisible(true);
            textField_Forfattare.setVisible(true);
            label_Genre.setVisible(true);
            textField_Genre.setVisible(true);

            artikelArray.add(b1);

            Meny.setArtikelArray(artikelArray);



            this.dispose();
            System.out.print(b1);
       }

Open in new window

0
Comment
Question by:Mickeys
[X]
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
  • 2
3 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 333 total points
ID: 36530643
You can use this example:
http://www.java2s.com/Code/JavaAPI/javax.swing.table/DefaultTableModeladdRowObjectrowData.htm

Declare the cvariable of the type DefaultTableModel

DefaultTableModel model;


instantinate it with dedfeault constructor

model = new DefaultTableModel();
then add columns:

model.addColumn("gfirst column name");

model.addColumn("second column name");

....

Then
populate String[] array for each row
and
model.addRow(array);

do it for all your rows

Then pass your model opbject to the class where you are creating jtable
and

use jtable.setModel(model)
you'll populate your jtable





0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 333 total points
ID: 36530687
 DefaultTableModel model = new DefaultTableModel();
model.addColumn("Title");
model.addColumn("ISBN");
model.addColumn("Genre");
...

//and the for each book 
//utyoui maye create a Vector:

//start loop over all books

Vector v = new Vector();

v.add(textBox_Namn.getText());
v.add( textBox_ISBN.getText());
...

model.addRow(v);

//end loop over all books

// you model instance  should be passed to the class
// which has jtable

jtable.setModel(model); //will populate JTable


 

Open in new window

0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 167 total points
ID: 36535434
Since you're already storing List<Bok> you can use that as the basis for a custom TableModel. If you attach your Bok class, it will help
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Title # Comments Views Activity
web application structure 18 111
login form jsp example 2 50
jsp error 6 43
jmeter usage 4 33
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

740 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