E
ebresie
Okay...this may be a newbie mistake somewhere involving JTables, but I
am perplexed...
I am making a custom dialog, which uses a custom panel I made, which
loads a large quantity of data into a vector, which is used as the data
for a DataModel. I load the data, show my dialog and its contained
panel, but the panel only shows about the first 18 rows of data out of
over 5000 rows.
Using a debugger, the data seems to be contained correctly in the
dataModel (and the vector it was derrived from), but the data only
shows the first few rows.
The scroll bars don't show up either.
I'm thinking I maybe forgetting to implement some listeners, or fire
some events or something, or maybe I'm not handling the Viewport of the
scroll pane, or something, but I'm not sure.
Anyone have any suggestions?
See code belows.
Eric Bresie
(e-mail address removed)
// ----------------------------------------------------
//
// Snippit from MyDialog Code
//
public class MyDialog extends JDialog {
JPanel mainPanel = new JPanel();
MyPanel sPanel = new MyPanel();
public MyDialog(Frame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setupGUI();
pack();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public MyDialog() {
this(new Frame(), "MyDialog", false);
}
private void setupGUI() throws Exception {
mainPanel.setLayout(borderLayout1);
getContentPane().add(mainPanel);
mainPanel.add(sPanel, java.awt.BorderLayout.CENTER);
}
//
// Snippit from MyPanel Code
//
public class MyPanel extends JPanel {
DefaultTableModel dataModel = new DefaultTableModel();
Vector myData = new Vector();
String[] headers = { "Column1", "Column2" };
Vector columnNames = new Vector(Arrays.asList(headers));
JTable myTable = new JTable(dataModel);
JScrollPane scrollPane = new JScrollPane(myTable);
BorderLayout borderLayout1 = new BorderLayout();
public MyPanel(DefaultTableModel dm) {
dataModel = dm;
myTable = new JTable(dataModel);
try {
setUpGUI();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public MyPanel() {
super();
try {
setupGUI();
} catch (Exception exception) {
exception.printStackTrace();
}
load();
}
private void setupGUI() throws Exception {
this.setLayout(borderLayout1);
scrollPane.setRowHeader(null);
scrollPane.setBorder(BorderFactory.createEtchedBorder());
scrollPane.setPreferredSize(new Dimension(200, 300));
scrollPane.createHorizontalScrollBar();
scrollPane.createVerticalScrollBar();
myTable.setBorder(BorderFactory.createEtchedBorder());
myTable.setMaximumSize(new Dimension(400, 300));
myTable.setMinimumSize(new Dimension(105, 100));
myTable.setPreferredSize(new Dimension(190, 290));
this.setBorder(BorderFactory.createEtchedBorder());
scrollPane.getViewport().add(myTable);
this.add(scrollPane, java.awt.BorderLayout.CENTER);
}
public void load() {
myData = DataSource.getMyData(); // also tried casting it to a
Vector but no luck
dataModel.setDataVector(myData , columnNames);
}
}
//
// Snippet from DataSource code
//
static public Vector getMyData() {
try {
myDataSet = getMyData(); // returns a attribute set
} catch (Exception ex) {
System.out.println("load:Exception" + ex + ")");
}
SomeAttributes atts = null;
Vector myData = new Vector(myDataSet.size());
try {
Vector v = null;
for (Iterator i = myDataSet.iterator(); i.hasNext(); ) {
v = new Vector();
atts = ((SomeAttributes) i.next());
String col1 = atts.getAttrValue("col1").toString();
v.add(col1);
String col2 = atts.getAttrValue("col2").toString();
v.add(col2);
myData.add((Vector) v);
}
} catch (Exception ex) {
System.out.println(
"load()" + ex + ")");
return null;
}
return myData;
}
am perplexed...
I am making a custom dialog, which uses a custom panel I made, which
loads a large quantity of data into a vector, which is used as the data
for a DataModel. I load the data, show my dialog and its contained
panel, but the panel only shows about the first 18 rows of data out of
over 5000 rows.
Using a debugger, the data seems to be contained correctly in the
dataModel (and the vector it was derrived from), but the data only
shows the first few rows.
The scroll bars don't show up either.
I'm thinking I maybe forgetting to implement some listeners, or fire
some events or something, or maybe I'm not handling the Viewport of the
scroll pane, or something, but I'm not sure.
Anyone have any suggestions?
See code belows.
Eric Bresie
(e-mail address removed)
// ----------------------------------------------------
//
// Snippit from MyDialog Code
//
public class MyDialog extends JDialog {
JPanel mainPanel = new JPanel();
MyPanel sPanel = new MyPanel();
public MyDialog(Frame owner, String title, boolean modal) {
super(owner, title, modal);
try {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setupGUI();
pack();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public MyDialog() {
this(new Frame(), "MyDialog", false);
}
private void setupGUI() throws Exception {
mainPanel.setLayout(borderLayout1);
getContentPane().add(mainPanel);
mainPanel.add(sPanel, java.awt.BorderLayout.CENTER);
}
//
// Snippit from MyPanel Code
//
public class MyPanel extends JPanel {
DefaultTableModel dataModel = new DefaultTableModel();
Vector myData = new Vector();
String[] headers = { "Column1", "Column2" };
Vector columnNames = new Vector(Arrays.asList(headers));
JTable myTable = new JTable(dataModel);
JScrollPane scrollPane = new JScrollPane(myTable);
BorderLayout borderLayout1 = new BorderLayout();
public MyPanel(DefaultTableModel dm) {
dataModel = dm;
myTable = new JTable(dataModel);
try {
setUpGUI();
} catch (Exception exception) {
exception.printStackTrace();
}
}
public MyPanel() {
super();
try {
setupGUI();
} catch (Exception exception) {
exception.printStackTrace();
}
load();
}
private void setupGUI() throws Exception {
this.setLayout(borderLayout1);
scrollPane.setRowHeader(null);
scrollPane.setBorder(BorderFactory.createEtchedBorder());
scrollPane.setPreferredSize(new Dimension(200, 300));
scrollPane.createHorizontalScrollBar();
scrollPane.createVerticalScrollBar();
myTable.setBorder(BorderFactory.createEtchedBorder());
myTable.setMaximumSize(new Dimension(400, 300));
myTable.setMinimumSize(new Dimension(105, 100));
myTable.setPreferredSize(new Dimension(190, 290));
this.setBorder(BorderFactory.createEtchedBorder());
scrollPane.getViewport().add(myTable);
this.add(scrollPane, java.awt.BorderLayout.CENTER);
}
public void load() {
myData = DataSource.getMyData(); // also tried casting it to a
Vector but no luck
dataModel.setDataVector(myData , columnNames);
}
}
//
// Snippet from DataSource code
//
static public Vector getMyData() {
try {
myDataSet = getMyData(); // returns a attribute set
} catch (Exception ex) {
System.out.println("load:Exception" + ex + ")");
}
SomeAttributes atts = null;
Vector myData = new Vector(myDataSet.size());
try {
Vector v = null;
for (Iterator i = myDataSet.iterator(); i.hasNext(); ) {
v = new Vector();
atts = ((SomeAttributes) i.next());
String col1 = atts.getAttrValue("col1").toString();
v.add(col1);
String col2 = atts.getAttrValue("col2").toString();
v.add(col2);
myData.add((Vector) v);
}
} catch (Exception ex) {
System.out.println(
"load()" + ex + ")");
return null;
}
return myData;
}