Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #16341
| From | clusardi2k@aol.com |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: NetBeans Application with sortable Table and pre-existing frame/table code |
| Date | 2012-07-25 07:54 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <ff39b71a-20af-45b7-9123-4403d6e8b6d0@googlegroups.com> (permalink) |
| References | <e4d9d3b6-0457-45c8-9bf3-6f7bbe0da09a@googlegroups.com> <2c4cb42d-92d9-48a6-9d69-0f63c5461070@googlegroups.com> |
How do I get this modified code to work.
I modified the working/good code from the attached link to the below code. The reason I do not want to use the code exactly on this link is it creates a new window and doesn't use the form that I already am using. The pre-existing form has jPanel1 (swing JPanel) containing jPanel3 (swing JPanel). And, jPanel3 contains jTable1 (swing JTable).
http://www.java-tips.org/java-se-tips/javax.swing/sorting-and-filtering-tables.html
(jTable1 was dragged to the form from the swing control palette. Design view shows a table with 4 columns and 4 rows, but the area is blanked out when I run the project!)
The below code compiles and runs, but the form's jTable1 is not populated with the data.
Thanks for any help,
...
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
Runnable runner = new Runnable() {
public void run() {
//JFrame frame = new JFrame("Sorting JTable");
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Object rows[][] = {
{"AMZN", "Amazon", 41.28},
{"EBAY", "eBay", 41.57},
{"GOOG", "Google", 388.33},
{"MSFT", "Microsoft", 26.56},
{"NOK", "Nokia Corp", 17.13},
{"ORCL", "Oracle Corp.", 12.52},
{"SUNW", "Sun Microsystems", 3.86},
{"TWX", "Time Warner", 17.66},
{"VOD", "Vodafone Group", 26.02},
{"YHOO", "Yahoo!", 37.69}
};
String columns[] = {"Symbol", "Name", "Price"};
TableModel model =
new DefaultTableModel(rows, columns) {
public Class getColumnClass(int column) {
Class returnValue;
if ((column >= 0) && (column < getColumnCount())) {
returnValue = getValueAt(0, column).getClass();
} else {
returnValue = Object.class;
}
return returnValue;
}
};
//JTable table = new JTable(model);
RowSorter<TableModel> sorter =
new TableRowSorter<TableModel>(model);
jTable1.setRowSorter(sorter);
JScrollPane pane = new JScrollPane(jTable1);
//frame.add(pane, BorderLayout.CENTER);
//frame.setSize(300, 150);
jPanel3.setVisible(true);
jPanel3.add(pane, BorderLayout.CENTER);
jTable1.setVisible(true);
}
};
EventQueue.invokeLater(runner);
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
NetBeans Application with sortable Table and pre-existing frame/table code clusardi2k@aol.com - 2012-07-23 10:54 -0700
Re: NetBeans Application with sortable Table and pre-existing frame/table code Lew <lewbloch@gmail.com> - 2012-07-23 12:55 -0700
Re: NetBeans Application with sortable Table and pre-existing frame/table code clusardi2k@aol.com - 2012-07-25 07:54 -0700
Re: NetBeans Application with sortable Table and pre-existing frame/table code clusardi2k@aol.com - 2012-07-25 08:14 -0700
Re: NetBeans Application with sortable Table and pre-existing frame/table code clusardi2k@aol.com - 2012-07-25 08:37 -0700
Re: NetBeans Application with sortable Table and pre-existing frame/table code Nigel Wade <nmw@ion.le.ac.uk> - 2012-07-25 16:40 +0100
Re: NetBeans Application with sortable Table and pre-existing frame/table code clusardi2k@aol.com - 2012-07-25 09:31 -0700
csiph-web