OT: RE: JFC Swing a tabulky
Landa Martin
Martin.Landa
Středa Březen 17 14:25:11 CET 2004
Zkusil bych se zeptat tady http://www.builder.cz/ v sekci Java.
Nebo zkus omrknout examples v JDK tusim, ze to je tohle:
---------------------- SimpleTableDemo.java --------------------------
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
public class SimpleTableDemo extends JFrame {
private boolean DEBUG = true;
public SimpleTableDemo() {
super("SimpleTableDemo");
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Chasing toddlers", new Integer(2), new Boolean(false)},
{"Mark", "Andrews",
"Speed reading", new Integer(20), new Boolean(true)},
{"Angela", "Lih",
"Teaching high school", new Integer(4), new Boolean(false)}
};
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
if (DEBUG) {
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
printDebugData(table);
}
});
}
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this window.
getContentPane().add(scrollPane, BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
private void printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
System.out.println("Value of data: ");
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + model.getValueAt(i, j));
}
System.out.println();
}
System.out.println("--------------------------");
}
public static void main(String[] args) {
SimpleTableDemo frame = new SimpleTableDemo();
frame.pack();
frame.setVisible(true);
}
}
-------------------- SimpleTableDemo.java ------------------------------------------
ML
> -----Original Message-----
> From: analyzer@volny.cz [mailto:analyzer@volny.cz]
> Sent: Thursday, October 24, 2002 11:25 AM
> To: hw-news@list.gin.cz
> Subject: JFC Swing a tabulky
>
>
> Hezky den,
>
> Chtel bych se zeptat, zda-li by se nekde nedal na i-netu
> sehnal popis tvorby tabulek v JFC Swing pomoci JTable, zkousel jsem
> cosi s pomoci Eckelovy knihy Thinking in Java, ale pokus se nejak
> nezdaril...
>
> S pozdravem
> Martin Krizovsky
>
>
Další informace o konferenci Hw-list