文档详情

JTable中合并单元格.doc

发布:2017-12-05约1.28万字共19页下载文档
文本预览下载声明
/* * SimpleTableDemo.java is a 1.4 application that requires no other files. */ //编辑的时候直接从覆盖原有内容 import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import java.io.*; import java.util.*; public class Combine extends JPanel { private boolean DEBUG = false; JTable table; public Combine() { super(new GridLayout(1,0)); table = new JTable( new MyTableModel() ); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); /////////////////////////////////////////////////////////// table.setDefaultEditor( String.class, new SelEditor() ); //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); } /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame(MyCustomTable2); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. Combine newContentPane = new Combine(); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane); //Display the window. frame.pack(); frame.setVisible(true); try { Thread.sleep( 1000 ); } catch ( InterruptedException e ) { e.printStackTrace(); } ((MyTableModel)newContentPane.table.getModel()).combineRow( First Name, Last Name ); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application′s GUI. javax.swing.SwingUtil
显示全部
相似文档