Hi Leute,
Ich habe in meinem Java Code einen JTable hinzugefügt, jedoch wird dies in meinem JPanel nicht richtig angezeigt. Könnt ihr mir vielleicht ein hinweis geben ?
Danke
Ich habe in meinem Java Code einen JTable hinzugefügt, jedoch wird dies in meinem JPanel nicht richtig angezeigt. Könnt ihr mir vielleicht ein hinweis geben ?
Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package test;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
/**
*
* @author SerSa
*/
public class Test extends JFrame implements ActionListener{
public static final DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
public final JButton btnclose = new JButton("Close");
public final JTextArea txtarea = new JTextArea(5,10);
public Test() throws Exception {
super("Touch Record");
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
Object[][] data = {
{"Kathy", "Smith",
"Snowboarding", new Integer(5), new Boolean(false)},
{"John", "Doe",
"Rowing", new Integer(3), new Boolean(true)},
{"Sue", "Black",
"Knitting", new Integer(2), new Boolean(false)},
{"Jane", "White",
"Speed reading", new Integer(20), new Boolean(true)},
{"Joe", "Brown",
"Pool", new Integer(10), new Boolean(false)}
};
final JTable table = new JTable(data, columnNames);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
final JPanel north = new JPanel();
final JPanel south = new JPanel();
final JPanel east = new JPanel();
final JPanel west = new JPanel();
final JPanel center = new JPanel();
add("North", north);
add("South", south);
add("East", east);
add("West", west);
add("Center", center);
north.setBorder(BorderFactory.createTitledBorder("Date&Time Display"));
final BoxLayout layout = new BoxLayout(north, BoxLayout.X_AXIS);
final JLabel datetime = new JLabel("");
datetime.setFont(new Font("Verdana", Font.PLAIN, 50));
north.add(datetime);
center.setBorder(BorderFactory.createTitledBorder("Attendence Record"));
center.setLayout(new BorderLayout());
center.add(table);
// table.setText(IsmbSnepConnection.received);
south.setBorder(BorderFactory.createTitledBorder("Selection"));
south.add(btnclose);
final BoxLayout la = new BoxLayout(south, BoxLayout.X_AXIS);
btnclose.addActionListener(this);
setSize(700, 600);
setVisible(true);
new Timer().scheduleAtFixedRate(new TimerTask()
{
@Override
public void run() {
datetime.setText(dateFormat.format(new Date()));
}
}, 0, 100);
}
public static void main(String[] args) throws Exception {
final Test me = new Test();
//PhoneToSender f = new PhoneToSender();
}
@Override
public void actionPerformed(ActionEvent e) {
}
}
Danke