我的观点没有显示Jtable

时间:2015-06-30 17:37:03

标签: java windowbuilder

我使用窗口构建器构建了简单的UI。但我面临一个问题,就是在我的框架中显示表格。我已经阅读了所有stackoverflow的主题并尝试了所有答案。一旦我运行代码,仍然无法查看此表。请帮我解决这个问题。感谢..

package com.chasoft.office.reminder;


import java.awt.Color;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.JTable;

public class MainReminder extends JFrame {

    private JPanel contentPane;
    private JTable table;
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    MainReminder frame = new MainReminder();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public MainReminder() {
        setTitle("Table View");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(0, 0, 901, 700);
        // setBackground(new Color(200));
        contentPane = new JPanel();
        contentPane.setForeground(Color.BLACK);
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JButton btnBrowse = new JButton("View Service Due Items");
        btnBrowse.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                String [] row1 = {"Jan", "31"}; 
                String [] row2 = {"Feb", "30"};
                    Object header[] = {"Item Name", "Item No", "Service Due Date", "Last Service Date", "Description"};
                    DefaultTableModel model = new DefaultTableModel(header, 0);                 
                    model.addRow(row1);                     
                    model.addRow(row2);

                    table.setBounds(554, 112, -535, 239);
                    table.setShowHorizontalLines(true);
                    table.setShowVerticalLines(true);
                    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                    table.setModel(model);

                    JScrollPane scrollPane = new JScrollPane(table);
                    scrollPane.setBounds(554, 112, -535, 239);
                    contentPane.add(scrollPane);

            }
        });
        btnBrowse.setBounds(271, 7, 172, 23);
        contentPane.add(btnBrowse);

        JLabel lblConsoleXml = new JLabel("Service Due Items");
        lblConsoleXml.setBounds(10, 87, 125, 14);
        contentPane.add(lblConsoleXml);

        table= new JTable();
        table.setBounds(835, 112, -816, 239);
        contentPane.add(table);

    }
}

0 个答案:

没有答案
相关问题