Skip to content

Instantly share code, notes, and snippets.

@mabako
Created May 29, 2012 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mabako/2830311 to your computer and use it in GitHub Desktop.
Save mabako/2830311 to your computer and use it in GitHub Desktop.
TableView thing for databases
package net.mabako.zwickau.autohaendler;
import javax.swing.JButton;
public class Dashboard extends JPanel
{
/**
* Serial
*/
private static final long serialVersionUID = -2754350246072768836L;
/**
* Erstellt das Dashboard.
*/
public Dashboard() {
setLayout(new MigLayout("", "[20%:20%:20%][grow][20%:20%:20%]", "[][][][][]"));
JButton lblBestand = new JButton("Bestand");
lblBestand.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
main.addContent(new TableView("autos"));
}
});
add(lblBestand, "cell 1 1");
JButton lblKunden = new JButton("Kunden");
lblKunden.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
main.addContent(new TableView("kunde"));
}
});
add(lblKunden, "cell 1 2");
JButton lblBestellungen = new JButton("Bestellungen");
lblBestellungen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
main.addContent(new TableView("bestellungen"));
}
});
add(lblBestellungen, "cell 1 3");
JButton lblHersteller = new JButton("Hersteller");
lblHersteller.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
main.addContent(new TableView("hersteller"));
}
});
add(lblHersteller, "cell 1 4");
}
}
package net.mabako.zwickau.autohaendler;
import java.awt.Component;
public class TableView extends JPanel
{
/**
* Serial
*/
private static final long serialVersionUID = 8718776316766923104L;
/**
* Die Tabelle, in welcher die Daten dargestellt werden
*/
private JTable table;
/**
* Erstellt eine neue Tabellenansicht
* @param tableName Name der entsprechenden Datenbanktabelle
*/
public TableView(String tableName) {
setLayout(new MigLayout("", "[grow]", "[grow]"));
JScrollPane scrollPane = new JScrollPane();
add(scrollPane, "cell 0 0,grow");
Prepared p = db.prepare("SELECT * FROM " + tableName);
Results model = p.executeWithResult();
model.setTableName(tableName);
table = new JTable(model);
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
p.close();
scrollPane.setViewportView(table);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment