retrieve data from a jTable

  • Thread starter Jacques Chaurette
  • Start date
J

Jacques Chaurette

hi, I am trying to retrieve data from a jTable with this instruction:

jLabelPipec1.setText(""+ valueOf(data[1,1]));

the data array is an objet as required for a table.

and of course it doesn't work. Any suggestions appreciated.


Jacques
 
R

Roedy Green

and of course it doesn't work.

By that you mean?

There is no change visible?
You get an exception?
You get a compile error?

I am going to tease you, though it is not just you who do this.
Jacques invited his friends to come see his fine new house. When they
came in the door he issued each with a pirate's eye patch to cover one
eye and a paper tube from the centre of a roll of paper towels. Then
he instructed them to look out the other eye, only through the tube.
Then he turned out all the lights and guided them on a tour of the
house lit by flashlight (electric torch).

Well, what do you think of my skill at interior design? he asked at
the end of the tour.
 
M

Monique Y. Mudama

hi, I am trying to retrieve data from a jTable with this
instruction:

jLabelPipec1.setText(""+ valueOf(data[1,1]));

the data array is an objet as required for a table.

and of course it doesn't work. Any suggestions appreciated.

Um.

Okay, I'll start with the first question: in what class does the above
line live? Is there any reason I should know what valueOf does
without knowing which class it belongs to?

I don't recognize the syntax data[1,1] as anything you can do in Java,
although it's late and my brain is fried, so I may be wrong.

Oh! One more! Please define "doesn't work." Doesn't compile? If so,
what does the compiler say?
 
J

Jacques Chaurette

Right sorry, doesn't work means doesn't compile. I am using JBuilder and the
compiler just refuses to run this, claims its missing a parenthesis. My java
knowledge is a little sketchy as I keep forgetting things that I knew a few
years ago especially when I stop doing java for a few years.

Data is an object that contains string data for a table and I am trying to
retrieve some table data. I thought that valueOf was a sort of universal
function that could accomplish this.

I am pretty sure that this syntax is OK data[1,1] for retrieving the item in
the 1,1 position.

The table elements are defined as follows:

String[] columnNames = {"Dia. (in)",
"Instal. cost"};

Object[][] data = {
{"3", "$25"},
{"4", "$30"},
{"5", "$35"},
{"6", "$45"},
{"8", "$55"}

};

Jacques

Monique Y. Mudama said:
hi, I am trying to retrieve data from a jTable with this
instruction:

jLabelPipec1.setText(""+ valueOf(data[1,1]));

the data array is an objet as required for a table.

and of course it doesn't work. Any suggestions appreciated.

Um.

Okay, I'll start with the first question: in what class does the above
line live? Is there any reason I should know what valueOf does
without knowing which class it belongs to?

I don't recognize the syntax data[1,1] as anything you can do in Java,
although it's late and my brain is fried, so I may be wrong.

Oh! One more! Please define "doesn't work." Doesn't compile? If so,
what does the compiler say?

--
monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
 
J

Jacques Chaurette

Ah, got it, you were right I am calling the data item the wrong way,
data[1][1] is the right call.

Jacques

Jacques Chaurette said:
Right sorry, doesn't work means doesn't compile. I am using JBuilder and
the compiler just refuses to run this, claims its missing a parenthesis.
My java knowledge is a little sketchy as I keep forgetting things that I
knew a few years ago especially when I stop doing java for a few years.

Data is an object that contains string data for a table and I am trying to
retrieve some table data. I thought that valueOf was a sort of universal
function that could accomplish this.

I am pretty sure that this syntax is OK data[1,1] for retrieving the item
in the 1,1 position.

The table elements are defined as follows:

String[] columnNames = {"Dia. (in)",
"Instal. cost"};

Object[][] data = {
{"3", "$25"},
{"4", "$30"},
{"5", "$35"},
{"6", "$45"},
{"8", "$55"}

};

Jacques

Monique Y. Mudama said:
hi, I am trying to retrieve data from a jTable with this
instruction:

jLabelPipec1.setText(""+ valueOf(data[1,1]));

the data array is an objet as required for a table.

and of course it doesn't work. Any suggestions appreciated.

Um.

Okay, I'll start with the first question: in what class does the above
line live? Is there any reason I should know what valueOf does
without knowing which class it belongs to?

I don't recognize the syntax data[1,1] as anything you can do in Java,
although it's late and my brain is fried, so I may be wrong.

Oh! One more! Please define "doesn't work." Doesn't compile? If so,
what does the compiler say?

--
monique

Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
 
R

Roedy Green

compiler just refuses to run this, claims its missing a parenthesis.

To solve this we need to see:

1. the exact line the compiler is complaining about.

2. the exact text of the error message.

3. the context: i.e. the places where the various things mentioned in
the line are defined.

4. ideally a COMPLETE program since the problem is rarely where the
person with the problem thinks it is.

The devil is in the details. You can diagnose squat from a rough
description.
 
J

John

Jacques said:
hi, I am trying to retrieve data from a jTable with this instruction:

jLabelPipec1.setText(""+ valueOf(data[1,1]));

the data array is an objet as required for a table.

and of course it doesn't work. Any suggestions appreciated.


Jacques

you need something more like this..

String[][] data inited elsewhere
String[] headers inited elsewhere
JLabel myLabel inited elsewhere

JTable myTable = new JTable(data, header);

myLabel.setText(myTable.getValueAt(0,0).toString());

Your initial code is nowhere near compiling or working.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top