参考:
http://www2.gol.com/users/tame/

解决方案 »

  1.   

    jTable1.getColumn("Con1").setCellRenderer(new ButtonRenderer());
          jTable1.getColumn("Con1").setCellEditor(new ButtonEditor(new JCheckBox()));
      

  2.   

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
     /** * @version 1.0 11/09/98 */
     public class ButtonEditor extends DefaultCellEditor {
        protected JButton button;
        private String    label;
        private boolean   isPushed;
        private int rowcount;    public ButtonEditor(JCheckBox checkBox) {
            super(checkBox);
            button = new JButton();
            button.setOpaque(true);        button.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                      fireEditingStopped();}});
        }    public Component getTableCellEditorComponent(JTable table, Object value,
         boolean isSelected,  int row, int column) {
          rowcount = row;
          if (isSelected) {
               button.setForeground(table.getSelectionForeground());
               button.setBackground(new Color(182, 208, 200));
               //button.setBackground(table.getSelectionBackground());
           } else{
               button.setForeground(table.getForeground());
               //button.setBackground(new Color(184, 208, 200));
               //button.setBackground(new Color(212, 208, 200));
               button.setBackground(table.getBackground());
           }
               label = (value ==null) ? "" : value.toString();
               button.setText( label );
               isPushed = true;
               return button;
         }    public Object getCellEditorValue() {
             if (isPushed)  {
             //
             //JOptionPane.showMessageDialog(button ,label + ": tOuch!");
             // System.out.println(label + ": Ouch!");
             }
             isPushed = false;
             return new String( label ) ;
        }    public boolean stopCellEditing() {
             isPushed = false;
             return super.stopCellEditing();
        }   protected void fireEditingStopped() {
              super.fireEditingStopped();
       }
    }
      

  3.   

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
     /** * @version 1.0 11/09/98 */
     public class ButtonRenderer extends JButton implements TableCellRenderer {
        public ButtonRenderer() {
          setOpaque(true);
        }    public Component getTableCellRendererComponent(JTable table, Object value,
           boolean isSelected,
           boolean hasFocus,
           int row,
           int column) {
           if (isSelected) {
            setForeground(table.getSelectionForeground());
            setBackground(new Color(184, 208, 200));
            setBackground(table.getSelectionBackground());
           } else{
            setForeground(table.getForeground());
            setBackground(new Color(217, 236, 210));
            //setBackground(UIManager.getColor("Button.background"));
           }
             setText( (value ==null) ? "" : value.toString() );
             this.setToolTipText("Perform forecasting for this period only!");
             return this;
             }
      }
      

  4.   

    you should only add a new column with setting its picklist property
      

  5.   

    首先告诉你,在column里可以加button,但是我看你的目的是弹出一个popup画面.
    所以根本用不着那么麻烦.这样就可以了.
    public class t extends JTable{
      public t(){
        addMouseListener(new MouseListener(){
        public void  mouseClicked(MouseEvent e)
        {
         if(!(e.getModifiers()==e.META_MASK)){//clicked mouse left
           JPopupMenu l= new JPopupMenu();                   
           l.show(参数);
         }
         if (e.getModifiers()==e.META_MASK){//clicked mouse right
           JPopupMenu r= new JPopupMenu();    
           r.show(参数);               
         }
         }
                public void  mouseEntered(MouseEvent e){}
                public void  mouseExited(MouseEvent e){}
                public void  mousePressed(MouseEvent e){}
                public void  mouseReleased(MouseEvent e){}
            });
        }
      }
    }