Why doesn't my JTable display

W

wooks

I would appreciate some urgent assistance with this simple code.

When it run it displays a blank frame. What do I need to do to get the
JTable to display?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class RunFileMatcher extends JFrame {

RunFileMatcher() {
JFrame frame = new JFrame("MatchTable");
frame.setSize(600,400);

String[] columnNames = {"File", "Size"};
String dataValues[][] = {
{ "A", "234" },
{ "B", "43" },
{ "C", "89.2" },
{ "D", "9033" }
};

JTable table = new JTable(dataValues,columnNames);
getContentPane().add(new JScrollPane(table), "Center");

frame.setVisible( true );
frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );

}
}
 
A

Andrew Thompson

wooks said:
I would appreciate some urgent assistance

...have you considered urgently paying a consultant?

(I was going to have a look over it, but now I have
decided to see if any others are willing to conform
to your schedule, first - just out of morbid curiousity..)

Andrew T.
 
D

Daniel Pitts

wooks said:
I would appreciate some urgent assistance with this simple code.

When it run it displays a blank frame. What do I need to do to get the
JTable to display?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class RunFileMatcher extends JFrame {

RunFileMatcher() {
JFrame frame = new JFrame("MatchTable");
frame.setSize(600,400);

String[] columnNames = {"File", "Size"};
String dataValues[][] = {
{ "A", "234" },
{ "B", "43" },
{ "C", "89.2" },
{ "D", "9033" }
};

JTable table = new JTable(dataValues,columnNames);
getContentPane().add(new JScrollPane(table), "Center");

frame.setVisible( true );
frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );

}
}

Ah, heres the problem....
Your class RunFileMatcher extends JFrame, and therefor IS-A JFrame, you
also create a *different* JFrame object (JFrame frame = new JFrame()).
You set up the table and the frame, but you add the table to your
RunFileMatcher object instead of the JFrame you initialized.

change the line:
public class RunFileMatcher extends JFrame {
to
public class RunFileMatcher {

and the line
getContentPane().add(new JScrollPane(table), "Center");
to
frame.getContentPane().add(new JScrollPane(table),
BorderLayer.CENTER);
 
D

Daniel Pitts

Andrew said:
..have you considered urgently paying a consultant?

(I was going to have a look over it, but now I have
decided to see if any others are willing to conform
to your schedule, first - just out of morbid curiousity..)

Andrew T.

I replied only because I am bored and enjoy this sort of thing.

Also, I didn't notice the "urgency", or I might have requested money
first :).
 
W

wooks

Daniel said:
wooks said:
I would appreciate some urgent assistance with this simple code.

When it run it displays a blank frame. What do I need to do to get the
JTable to display?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;

public class RunFileMatcher extends JFrame {

RunFileMatcher() {
JFrame frame = new JFrame("MatchTable");
frame.setSize(600,400);

String[] columnNames = {"File", "Size"};
String dataValues[][] = {
{ "A", "234" },
{ "B", "43" },
{ "C", "89.2" },
{ "D", "9033" }
};

JTable table = new JTable(dataValues,columnNames);
getContentPane().add(new JScrollPane(table), "Center");

frame.setVisible( true );
frame.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );

}
}

Ah, heres the problem....
Your class RunFileMatcher extends JFrame, and therefor IS-A JFrame, you
also create a *different* JFrame object (JFrame frame = new JFrame()).
You set up the table and the frame, but you add the table to your
RunFileMatcher object instead of the JFrame you initialized.

change the line:
public class RunFileMatcher extends JFrame {
to
public class RunFileMatcher {

and the line
getContentPane().add(new JScrollPane(table), "Center");
to
frame.getContentPane().add(new JScrollPane(table),
BorderLayer.CENTER);

Thank you ... it works. I'm on the last leg of some coursework that is
due on Monday, so now I can get on with the other bits.
 
L

Luc The Perverse

wooks said:
Assuming I had would you have made enough from my simple problem to buy
a burger?

Gimme a job or gimme charity

A burger is currently out of my price range.

I have a sign, "Will Program For Pennies (and by pennies I mean 12$/hr)"
 
L

Lew

Andrew said:
..have you considered urgently paying a consultant?
Assuming I had would you have made enough from my simple problem to buy
a burger?

That depends on the urgency, not the simplicity, and on the price you are
willing to pay.

I would gladly solve your urgent problem for $20K U.S., and that'll buy the
burger stand.

- Lew
 
L

Lew

wooks said:
Thank you ... it works. I'm on the last leg of some coursework that is
due on Monday, so now I can get on with the other bits.

Damn! There goes my $20K!

- Lew
 

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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top