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

📄 tablemodelfreeexample.java

📁 本程序是有IBM开发的一个基于数据表格的组件,里面有相关的例子和DOC,本站资料仅为大家学习之用
💻 JAVA
字号:
package demo.hr;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JTable;

import com.ibm.j2x.swing.util.TableUtilities;
import com.ibm.j2x.util.CollectionUtilities;

/**
 * The TableModelFreeExample serves as the counter-point to the TableModelExample.  At
 * quick glance, you can see that it is over 200 lines of code less.  This code can be
 * used as an example of how you can implement the TMF in other code.
 * <p>See the comments in the code for further guide points.
 * @author MAbernethy
 */
public class TableModelFreeExample implements ActionListener
{
	private JTable personalTable;
	private JTable financialTable;
	private JTable hireTable;
	private List candidates;
	private List employees;

	public TableModelFreeExample(JTable hireTable, JTable personalTable, JTable financialTable, List listCandidates)
	{
		this.hireTable = hireTable;
		this.personalTable = personalTable;
		this.financialTable = financialTable;
		
		// to take full advantage of the TMF, all data should be decorated
		// with its Observable counterpart.  This allows for easy updates
		// to the table through simple manipulation of the data itself,
		// without worrying about calling updates on the table model every
		// time the data changes.
		this.candidates = CollectionUtilities.observableList(listCandidates);	
		this.employees = CollectionUtilities.observableList(new ArrayList());
		
		//These 3 lines of code accomplish what took traditional TableModel
		// code 210 lines of code to do.  What more could you ask for?
		// Note - the class and name arguments into this function
		// act soley as an identification means for referencing the table models in the
		// the XML file.
		TableUtilities.setViewToModel("demo/hr/resources/evil_hr_table.xml", "Hire", hireTable, candidates);	
		TableUtilities.setViewToModel("demo/hr/resources/evil_hr_table.xml", "Personal", personalTable, employees);
		TableUtilities.setViewToModel("demo/hr/resources/evil_hr_table.xml", "Financial", financialTable, employees);
	}

	public void actionPerformed(ActionEvent e)
	{
		// Only one line of code to update all 3 tables.  It takes 4 lines of code
		// using the classical TableModel.  This is simplified by using the
		// ObservableCollections.
		JButton b = (JButton)e.getSource();
		if (b.getText().equals("Hire"))
			employees.add(candidates.remove(hireTable.getSelectedRow()));
		else
			employees.remove(financialTable.getSelectedRow());			
	}

}

⌨️ 快捷键说明

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