H
Hammond
Gast
Hi!
Ich hab schon versucht mein Problem über Google, etc. zu lösen. Aber das ist mir nicht gelungen.
Ich möchte zu meinem JFrame eine Tabelle hinzufügen. Jedoch wird diese nur ohne die Überschrift der Spalten (bei mir columnNames) angezeigt. Ich hab es auch schon mit JScrollPane versucht. Aber ich kriegs einfach nicht hin.
Hoffentlich kann mir hier jemand helfen ^^
Hier ist die Klasse in der alles zusammen läuft:
Und hier die Klasse mit der alles dargestellt werden soll:
Ich hab schon versucht mein Problem über Google, etc. zu lösen. Aber das ist mir nicht gelungen.
Ich möchte zu meinem JFrame eine Tabelle hinzufügen. Jedoch wird diese nur ohne die Überschrift der Spalten (bei mir columnNames) angezeigt. Ich hab es auch schon mit JScrollPane versucht. Aber ich kriegs einfach nicht hin.
Hoffentlich kann mir hier jemand helfen ^^
Hier ist die Klasse in der alles zusammen läuft:
Java:
import java.awt.*;
public class Geld_main {
public static void main(String[] args) {
Window main_Fenster = new Window();
main_Fenster.setVisible(true);
}
}
Und hier die Klasse mit der alles dargestellt werden soll:
Java:
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.*;
import javax.swing.table.*;
public class Window extends JFrame{
/*Strings für Dropdownmenu*/
String[] day = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
String[] month = {"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"};
String[] year = {"2011", "2012", "2013", "2014", "2015", "2016"};
String[] category = {"", "Auto", "Essen", "Kleidung", "Motorrad", "PC"};
String[] columnNames = {"Tag", "Monat", "Jahr", "Bezeichnung", "Betrag", "Kategorie", "Sonstiges"};
String[][] row = {{"a", "b", "c", "d", "e", "f", "g"} , {"1", "2", "3", "4", "5", "6", "7"}};
/*Label*/
JLabel label_date = new JLabel("<html><u>Datum<html>");
JLabel label_notation = new JLabel("<html><u>Bezeichnung<html>");
JLabel label_amount = new JLabel("<html><u>Betrag in €<html>");
JLabel label_category = new JLabel("<html><u>Kategorie<html>");
JLabel label_other = new JLabel("<html><u>Sonstiges<html>");
/*Textfelder*/
JTextField tf_notation = new JTextField();
JTextField tf_amount = new JTextField();
JTextField tf_other = new JTextField();
/*Dropdownmenu*/
JComboBox dd_day = new JComboBox(day);
JComboBox dd_month = new JComboBox(month);
JComboBox dd_year = new JComboBox(year);
JComboBox dd_category = new JComboBox(category);
/*Button*/
JButton b_save = new JButton("Speichern");
/*Tabelle*/
JTable table = new JTable(row, columnNames);
JScrollPane pane = new JScrollPane(table);
/*
* Konstruktor Klasse Window
*/
public Window(){
this.getContentPane().setLayout(null);
this.initWindow();
this.addWindowListener(new WindowListener(){
public void windowClosed(WindowEvent arg0) {
}
public void windowActivated(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
System.exit(0);
}
public void windowDeactivated(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowOpened(WindowEvent e) {
}
});
}
/*
* Methode um neues Fenster anzulegen
*/
protected void initWindow(){ //
setTitle("Geld"); //Bezeichnung
setExtendedState(Frame.MAXIMIZED_BOTH); //Fenster maximieren
getContentPane().setBackground(Color.WHITE);
/*
* Layout der Felder/Button/...
*/
dd_day.setBounds(10,40,40,25);
dd_month.setBounds(55,40,100,25);
dd_year.setBounds(160,40,60,25);
dd_category.setBounds(565,40,100,25);
label_date.setBounds(10,10,60,25);
label_notation.setBounds(225, 10, 100, 25);
label_amount.setBounds(480, 10, 80, 25);
label_category.setBounds(565, 10, 60, 25);
label_other.setBounds(670, 10, 60, 25);
tf_notation.setBounds(225, 40, 250, 25);
tf_amount.setBounds(480, 40, 80, 25);
tf_other.setBounds(670, 40, 400, 25);
b_save.setBounds(1100, 40, 100, 25);
table.setBounds(10, 80, 500, 500);
/*
* Einfügen alles benötigten Felder/Button/...
*/
this.getContentPane().add(dd_day);
this.getContentPane().add(dd_month);
this.getContentPane().add(dd_year);
this.getContentPane().add(dd_category);
this.getContentPane().add(label_date);
this.getContentPane().add(label_notation);
this.getContentPane().add(label_amount);
this.getContentPane().add(label_category);
this.getContentPane().add(label_other);
this.getContentPane().add(tf_notation);
this.getContentPane().add(tf_amount);
this.getContentPane().add(tf_other);
this.getContentPane().add(b_save);
this.getContentPane().add(table);
}
}