1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
* public class TextEdit extends AbstractCellEditor implements TableCellEditor,ActionListener {
*
* JButton button;
* String value;
* JWindow dialog;
* protected static final String EDIT = "edit";
* JScrollPane scroll;
* JTextArea text;
*
* /* (non-Javadoc)
* * @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(javax.swing.JTable, java.lang.Object, boolean, int, int)
* */
* public TextEdit(JFrame arg){
*
*
* button = new JButton();
* button.setActionCommand(EDIT);
* button.addActionListener(this);
* button.setBorderPainted(false);
* dialog = new JWindow();
* dialog.setSize(301,71);
* dialog.setLayout(null);
* text=new JTextArea();
* scroll=new JScrollPane();
* scroll.setViewportView(text);
* scroll.setBounds(0, 0, 300, 70);
* dialog.add(scroll);
* dialog.setEnabled(true);
*
* }
*
*
*
*
* public Component getTableCellEditorComponent(JTable arg0, Object arg1, boolean arg2, int arg3, int arg4) {
* // TODO Auto-generated method stub
* value= arg1.toString();
* dialog.setLocation(MouseInfo.getPointerInfo().getLocation());
*
* return button;
* }
*
* /* (non-Javadoc)
* * @see javax.swing.CellEditor#getCellEditorValue()
* */
* public Object getCellEditorValue() {
* // TODO Auto-generated method stub
*
* return value;
* }
*
* /* (non-Javadoc)
* * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
* */
* public void actionPerformed(ActionEvent e) {
* // TODO Auto-generated method stub
* if (EDIT.equals(e.getActionCommand())) {
* //The user has clicked the cell, so
* //bring up the dialog.
* button.setText(value);
* text.setText(value);
* dialog.setVisible(true);
* dialog.toFront();
* //edit.setVisible(true);
* //Make the renderer reappear.
* fireEditingStopped();
*
* } else { //User pressed dialog's "OK" button.
* value = text.getText();
*
* }
* } |
Partager