tabledemo.java

来自「一个小公司要求给写的很简单的任务管理系统。」· Java 代码 · 共 751 行 · 第 1/3 页

JAVA
751
字号
/* * @(#)TableDemo.java	1.23 05/11/30 *  * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: *  * -Redistribution of source code must retain the above copyright notice, this *  list of conditions and the following disclaimer. *  * -Redistribution in binary form must reproduce the above copyright notice,  *  this list of conditions and the following disclaimer in the documentation *  and/or other materials provided with the distribution. *  * Neither the name of Sun Microsystems, Inc. or the names of contributors may  * be used to endorse or promote products derived from this software without  * specific prior written permission. *  * This software is provided "AS IS," without a warranty of any kind. ALL  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. *  * You acknowledge that this software is not designed, licensed or intended * for use in the design, construction, operation or maintenance of any * nuclear facility. *//* * @(#)TableDemo.java	1.23 05/11/30 */import javax.swing.*;import javax.swing.event.*;import javax.swing.text.*;import javax.swing.table.*;import javax.swing.border.*;import javax.swing.colorchooser.*;import javax.swing.filechooser.*;import javax.accessibility.*;import java.awt.*;import java.awt.event.*;import java.awt.print.PrinterException;import java.beans.*;import java.util.*;import java.io.*;import java.applet.*;import java.net.*;import java.text.MessageFormat;/** * Table demo * * @version 1.23 11/30/05 * @author Philip Milne * @author Steve Wilson */public class TableDemo extends DemoModule {    JTable      tableView;    JScrollPane scrollpane;    Dimension   origin = new Dimension(0, 0);        JCheckBox   isColumnReorderingAllowedCheckBox;    JCheckBox   showHorizontalLinesCheckBox;    JCheckBox   showVerticalLinesCheckBox;    JCheckBox   isColumnSelectionAllowedCheckBox;    JCheckBox   isRowSelectionAllowedCheckBox;    JLabel      interCellSpacingLabel;    JLabel      rowHeightLabel;    JSlider     interCellSpacingSlider;    JSlider     rowHeightSlider;    JComboBox	selectionModeComboBox = null;    JComboBox	resizeModeComboBox = null;    JLabel      headerLabel;    JLabel      footerLabel;    JTextField  headerTextField;    JTextField  footerTextField;    JCheckBox   fitWidth;    JButton     printButton;    JPanel      controlPanel;    JScrollPane tableAggregate;    String path = "ImageClub/food/";    final int INITIAL_ROWHEIGHT = 33;    /**     * main method allows us to run as a standalone demo.     */    public static void main(String[] args) {	TableDemo demo = new TableDemo(null);	demo.mainImpl();    }    /**     * TableDemo Constructor     */    public TableDemo(SwingSet2 swingset) {	super(swingset, "TableDemo", "toolbar/JTable.gif");		getDemoPanel().setLayout(new BorderLayout());	controlPanel = new JPanel();        controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.X_AXIS));	JPanel cbPanel = new JPanel(new GridLayout(3, 2));        JPanel labelPanel = new JPanel(new GridLayout(2, 1)) {            public Dimension getMaximumSize() {                return new Dimension(getPreferredSize().width, super.getMaximumSize().height);            }        };        JPanel sliderPanel = new JPanel(new GridLayout(2, 1)) {            public Dimension getMaximumSize() {                return new Dimension(getPreferredSize().width, super.getMaximumSize().height);            }        };	JPanel comboPanel = new JPanel(new GridLayout(2, 1));        JPanel printPanel = new JPanel(new ColumnLayout());	getDemoPanel().add(controlPanel, BorderLayout.NORTH);	Vector relatedComponents = new Vector();        // check box panel    	isColumnReorderingAllowedCheckBox = new JCheckBox(getString("TableDemo.reordering_allowed"), true);        isColumnReorderingAllowedCheckBox.addActionListener(new ActionListener() {	    public void actionPerformed(ActionEvent e) {	        boolean flag = ((JCheckBox)e.getSource()).isSelected();                tableView.getTableHeader().setReorderingAllowed(flag);                tableView.repaint();	    }        });    	showHorizontalLinesCheckBox = new JCheckBox(getString("TableDemo.horz_lines"), true);        showHorizontalLinesCheckBox.addActionListener(new ActionListener() {	    public void actionPerformed(ActionEvent e) {	        boolean flag = ((JCheckBox)e.getSource()).isSelected();                tableView.setShowHorizontalLines(flag); ;                tableView.repaint();	    }        });    	showVerticalLinesCheckBox = new JCheckBox(getString("TableDemo.vert_lines"), true);        showVerticalLinesCheckBox.addActionListener(new ActionListener() {	    public void actionPerformed(ActionEvent e) {	        boolean flag = ((JCheckBox)e.getSource()).isSelected();                tableView.setShowVerticalLines(flag); ;                tableView.repaint();	    }        });	// Show that showHorizontal/Vertical controls are related	relatedComponents.removeAllElements();	relatedComponents.add(showHorizontalLinesCheckBox);	relatedComponents.add(showVerticalLinesCheckBox);	buildAccessibleGroup(relatedComponents);        isRowSelectionAllowedCheckBox = new JCheckBox(getString("TableDemo.row_selection"), true);        isRowSelectionAllowedCheckBox.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                boolean flag = ((JCheckBox)e.getSource()).isSelected();                tableView.setRowSelectionAllowed(flag); ;                tableView.repaint();            }        });        isColumnSelectionAllowedCheckBox = new JCheckBox(getString("TableDemo.column_selection"), false);        isColumnSelectionAllowedCheckBox.addActionListener(new ActionListener() {            public void actionPerformed(ActionEvent e) {                boolean flag = ((JCheckBox)e.getSource()).isSelected();                tableView.setColumnSelectionAllowed(flag); ;                tableView.repaint();            }        });        // Show that row/column selections are related        relatedComponents.removeAllElements();        relatedComponents.add(isColumnSelectionAllowedCheckBox);        relatedComponents.add(isRowSelectionAllowedCheckBox);        buildAccessibleGroup(relatedComponents);        cbPanel.add(isColumnReorderingAllowedCheckBox);        cbPanel.add(isRowSelectionAllowedCheckBox);        cbPanel.add(showHorizontalLinesCheckBox);        cbPanel.add(isColumnSelectionAllowedCheckBox);        cbPanel.add(showVerticalLinesCheckBox);        // label panel        interCellSpacingLabel = new JLabel(getString("TableDemo.intercell_spacing_colon"));	labelPanel.add(interCellSpacingLabel);        rowHeightLabel = new JLabel(getString("TableDemo.row_height_colon"));        labelPanel.add(rowHeightLabel);        // slider panel    	interCellSpacingSlider = new JSlider(JSlider.HORIZONTAL, 0, 10, 1);	interCellSpacingSlider.getAccessibleContext().setAccessibleName(getString("TableDemo.intercell_spacing"));	interCellSpacingLabel.setLabelFor(interCellSpacingSlider);        sliderPanel.add(interCellSpacingSlider);        interCellSpacingSlider.addChangeListener(new ChangeListener() {	    public void stateChanged(ChangeEvent e) {	        int spacing = ((JSlider)e.getSource()).getValue();                tableView.setIntercellSpacing(new Dimension(spacing, spacing));                tableView.repaint();	    }        });	    	rowHeightSlider = new JSlider(JSlider.HORIZONTAL, 5, 100, INITIAL_ROWHEIGHT);	rowHeightSlider.getAccessibleContext().setAccessibleName(getString("TableDemo.row_height"));	rowHeightLabel.setLabelFor(rowHeightSlider);        sliderPanel.add(rowHeightSlider);        rowHeightSlider.addChangeListener(new ChangeListener() {	    public void stateChanged(ChangeEvent e) {	        int height = ((JSlider)e.getSource()).getValue();                tableView.setRowHeight(height);                tableView.repaint();	    }        });	// Show that spacing controls are related	relatedComponents.removeAllElements();	relatedComponents.add(interCellSpacingSlider);	relatedComponents.add(rowHeightSlider);	buildAccessibleGroup(relatedComponents);        // Create the table.        tableAggregate = createTable();        getDemoPanel().add(tableAggregate, BorderLayout.CENTER);        // ComboBox for selection modes.

⌨️ 快捷键说明

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