📄 arraylisttablesimple.java
字号:
import com.darwinsys.util.*;import javax.swing.*;import java.awt.*;import java.util.*;/** Simple demo of the com.darwinsys.util.ArrayListTable{Model,Panel}. * The "data" is an ArrayList made from the System Properties */public class ArrayListTableSimple extends JFrame { /** inner class for TableModel */ class Model extends ArrayListTableModel { /** This defines the order of the columns. Must agree with columnClasses */ protected String[] myColumnNames = { "Name", "Value" }; protected Class[] myColumnClasses = { String.class, String.class }; /** Return the width of the table */ public int getColumnCount() { return 2; } /** Construct a Model given the ArrayList */ public Model(ArrayList m) { super(m); columnNames = myColumnNames; columnClasses = myColumnClasses; } /** Returns a data value for the cell at row, col */ public Object getValueAt(int row, int col) { ArrayListTableDatum current = (ArrayListTableDatum)getCached(row); switch(col) { case 0: return current.name; case 1: return current.value; default: System.out.println("ERROR getValueAt(" + row + "," + col + "); invalid"); return null; } } /** Set a data value for the cell at row, col */ public void setValueAt(Object val, int row, int col) { ArrayListTableDatum current = (ArrayListTableDatum)getCached(row); switch(col) { case 0: current.name = (String)val; case 1: current.value = (String)val; } } } /** Construct the main program's GUI */ public ArrayListTableSimple() { super("ArrayListTableSimple"); // Create empty ArrayList ArrayList data = new ArrayList(); // Get the System Properties Properties p = System.getProperties(); // Get an Iterator for the sorted set of keys in p Iterator it = new TreeMap(p).keySet().iterator(); // Copy them into the ArrayList while (it.hasNext()) { String key = (String)it.next(); String val = p.getProperty(key); data.add(new ArrayListTableDatum(key, val)); } // Make the Model and View Model m = new Model(data); JPanel v = new ArrayListTablePanel(ArrayListTableDatum.class, data, m); // Make it show up in this JFrame setContentPane(new JScrollPane(v)); pack(); addWindowListener(new WindowCloser(this, true)); } public static void main(String[] args) { new ArrayListTableSimple().setVisible(true); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -