companytablecomponent.java

来自「CRMS客户关系管理系统(JAVA版),这是一个客户关系管理系统。」· Java 代码 · 共 114 行

JAVA
114
字号
package crms.applet.company;import crms.ui.*;import crms.vo.*;import java.util.*;import javax.swing.*;import javax.swing.border.*;import java.awt.*;import java.awt.event.*;public class CompanyTableComponent extends CRMSComponent {	public static final int COMPANY_SELECTED = 1;	CallbackDestination parent;	StaffMember user = null;	CompanyDataTableModel resultsModel = new CompanyDataTableModel();	JTable resultsTable = new JTable(resultsModel);	JScrollPane resultsScrollPane = new JScrollPane(resultsTable);	ArrayList companyList = null;	String title = null;	public CompanyTableComponent() {		this(null, null);	}	public CompanyTableComponent(CallbackDestination parent) {		this(parent, null);	}	public CompanyTableComponent(CallbackDestination parent, String title) {		this.parent = parent;		setTitle(title);	}	/** Set the company to have a list of companies. */	public void setCompanyList(ArrayList companies) {		companyList = companies;		resultsModel.clear();		for (int i=0; i < companyList.size(); i++) {			Company company = (Company)companyList.get(i);			resultsModel.addCompany(company);		}		resultsModel.fireTableDataChanged();		SwingUtilities.updateComponentTreeUI(resultsTable);	}	public void setUser(StaffMember user) {		this.user = user;	}	public StaffMember getUser() {		return user;	}	public Company getSelected() {		Company company = null;		if (resultsTable.getSelectedRow() >= 0) {			company = (Company)resultsModel.get(resultsTable.getSelectedRow());		}		return company;	}	public void clear() {		resultsModel.clear();		companyList = null;	}	public void init() {		// get a copy of this class so that it is accessable within the inner class		final CompanyTableComponent component = this;		resultsTable.addMouseListener( new MouseAdapter() {			public void mouseClicked(java.awt.event.MouseEvent ev) {				if (ev.getClickCount() == 2) {					if (parent != null) parent.callback(component, COMPANY_SELECTED, getSelected());				}			}		} );		setBackground(Color.WHITE);		setLayout(new BorderLayout());				add(resultsScrollPane, BorderLayout.CENTER);	}	public void setTitle(String title) {		if (title == null) {			this.title = "";		}		TitledBorder border = new TitledBorder( new EtchedBorder(EtchedBorder.LOWERED), title);		resultsScrollPane.setBorder(border);	}	public void setBackground(Color color) {		if (resultsTable == null) return;		resultsTable.setBackground(color);		resultsScrollPane.setBackground(color);		resultsScrollPane.getViewport().setBackground(color);	}	}

⌨️ 快捷键说明

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