⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demojtable.java

📁 java 开发工具书上的一些代码
💻 JAVA
字号:
/*
 * DemoJTable.java
 *
 * Created on 2006年4月7日, 下午9:42
 */

package org.netbeans.swing.table;

/**
 *
 * @author  boyingking
 */
public class DemoJTable extends javax.swing.JFrame {
    
    /** Creates new form DemoJTable */
    public DemoJTable() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableFactory = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("JTable\u5e94\u7528\u793a\u4f8b");
        jTableFactory.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"电脑", new Integer(123456), "北京", new Integer(20), new Double(4999.0), "不可优惠"},
                {"汽车", new Integer(321546), "上海", new Integer(15), new Double(632565.0), "可优惠"},
                {"手机", new Integer(985632), "韩国", new Integer(68), new Double(1853.0), "不可优惠"},
                {"MP3", new Integer(897452), "杭州", new Integer(120), new Double(368.0), "货源充足"},
                {"主板", new Integer(897546), "台湾", new Integer(88), new Double(620.0), "货源充足"},
                {"显卡", new Integer(895210), "深圳", new Integer(59), new Double(430.0), "缺货"},
                {"CPU", new Integer(895632), "美国", new Integer(650), new Double(1230.0), "不可优惠"},
                {"手表", new Integer(563241), "瑞士", new Integer(650), new Double(95800.0), "需要预定"},
                {"图书", new Integer(432568), "北京", new Integer(6580), new Double(58.0), "货源充足"},
                {"香烟", new Integer(589623), "云南", new Integer(658), new Double(320.0), "货源充足"}
            },
            new String [] {
                "商品名称", "商品编号", "产地", "数量", "单价", "备注"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class, java.lang.Double.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTableFactory);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DemoJTable().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableFactory;
    // End of variables declaration//GEN-END:variables
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -