当前位置: 代码迷 >> J2SE >> JTable编辑有关问题
  详细解决方案

JTable编辑有关问题

热度:86   发布时间:2016-04-23 22:39:27.0
JTable编辑问题

package pms.client.ui.dlg;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.rmi.RemoteException;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;

import javax.swing.CellEditor;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import org.apache.log4j.Logger;

import pms.client.main.ClientContext;
import pms.client.util.ClientConfigReader;
import pms.client.util.PmsDictionary;
import pms.common.util.CommonUtil;

public class DlgSetParameter extends JDialog implements ActionListener{
static Logger logger=Logger.getLogger(DlgSetParameter.class);
JTabbedPane configure=new JTabbedPane();
JPanel mainPanel=new JPanel();
JPanel buttonPanel_server=new JPanel(new FlowLayout());
JPanel buttonPanel_client=new JPanel(new FlowLayout());
JButton btnOK_server=new JButton("确定");
JButton btnCancel_server=new JButton("取消");
JButton btnOK_client=new JButton("确定");
JButton btnCancel_client=new JButton("取消");
JScrollPane jsp_client=new JScrollPane();
JScrollPane jsp_server=new JScrollPane();
JTable serverconfigTable=new JTable();
JTable clientconfigTable=new JTable();
JPanel serverconfigPanel=new JPanel(new BorderLayout());
JPanel clientconfigPanel=new JPanel(new BorderLayout());
public DlgSetParameter(Window window){
super(window);
jbInit();
}

private void jbInit(){

buttonPanel_client.setPreferredSize(new Dimension(300,80));
buttonPanel_server.setPreferredSize(new Dimension(300,80));
btnCancel_client.setPreferredSize(new Dimension(60,22));
btnCancel_server.setPreferredSize(new Dimension(60,22));
btnOK_server.setPreferredSize(new Dimension(60,22));
btnOK_client.setPreferredSize(new Dimension(60,22));
btnOK_client.addActionListener(this);
btnOK_server.addActionListener(this);
btnCancel_client.addActionListener(this);
btnCancel_server.addActionListener(this);
try {
serverconfigTable.setModel(new ParameterModel(ClientContext.getcCommonQueryIFC().findServerconfig()));
} catch (RemoteException e) {
logger.error(e);
}
clientconfigTable.setModel(new ParameterModel(ClientConfigReader.getProperties()));
clientconfigTable.addMouseListener(new MouseAdapter(){

@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
if(e.getClickCount()==1){
if(clientconfigTable.isEditing()){
int row_edit=clientconfigTable.getSelectedRow();
int col_edit=clientconfigTable.getSelectedColumn();
CellEditor ce = clientconfigTable.getCellEditor(row_edit, col_edit); 
ce.stopCellEditing();
  相关解决方案