Solved

How to fill my jtable

Posted on 2011-09-13
3
274 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jsp login check 12 67
Bot application - advice 3 81
batch vs regular insert in spring DAO 2 52
How to log java errors in tomcat 8 39
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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