JTable Combobox editor with PrppertychangeListener

Hello,
I need a help from experts.
I have a JTable. In the java table i need to have a ComboBox editor for example on the second column. And when i am changing value in the combobox i need to to do some calculations in JTable object.
To setup a PropertyChangeListener on combo object is not what i want, because i can not make calcultions inside JTable.
I need ComboBox based editor for JTable with property change listener.
Can anybody point me to some example o sugest something?
Thanks a lot

Sollution
package kelias.table.editor;
import javax.swing.DefaultCellEditor;
import javax.swing.JTable;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.Component;
import kelias.ComboBox.MyDBComboBox;
Implements a cell editor that uses a formatted text field
to edit Integer values.
public class CarJobEditor extends DefaultCellEditor implements ItemListener
MyDBComboBox comboJobs;
//Darbo kiekis
String jobQuantity=new String();
//Lentel�
JTable tableTmp;
//Einamoji eilut�
int rowTmp;
int jobQColNumber;
int resultColIndex;
public CarJobEditor(int jobQColNumber,int resultColIndex)
super(new MyDBComboBox());
this.jobQColNumber=jobQColNumber;
this.resultColIndex=resultColIndex;
comboJobs = (MyDBComboBox) getComponent();
comboJobs.loadData(kelias.db.DBStrings.selectJobsForCombo());
comboJobs.addItemListener(this);
//Override to invoke setValue on the formatted text field.
public Component getTableCellEditorComponent(JTable table,Object value, boolean isSelected,int row, int column)
     jobQuantity=(String)table.getValueAt(row,jobQColNumber);
     this.tableTmp=table;
     this.rowTmp=row;
MyDBComboBox tmp = (MyDBComboBox)super.getTableCellEditorComponent(table, value, isSelected, row, column);
tmp.setSelectedItem(value);
return tmp;
public void itemStateChanged(ItemEvent event)
     if(event.getStateChange() == ItemEvent.SELECTED)
          if (!this.jobQuantity.equals(""))
               float price=kelias.db.DBGetData.selectJobPricePM(comboJobs.getSelectedItem());
               float quantity=Float.parseFloat((String)jobQuantity);
               float f = (float) (Math.round(price*quantity*100.0f)/100.0f);
               tableTmp.setValueAt(f,rowTmp,resultColIndex);
}

Similar Messages

  • JComboBox With JTable as Editor

    Hi everybody
    I'm working with JTable and having a ComboBox as first CellEditor. for that purpose i used following code
            cmbFeeType.setModel(new javax.swing.DefaultComboBoxModel(DefaultFee.FeeTypeItemList()));       
            DefaultCellEditor DCEFeeType = new DefaultCellEditor(cmbFeeType);
            DCEFeeType.setClickCountToStart(2);here DefaultFee.FeeTypeItemList is a vector returns array. This is working fine except that the ComboBox remains visible till I dobule clik on a column for editing. Then It becomes invisible and works fine.
    my JComboBox is a seperate Control on a JFrame I do not want to use
    Class FeeTypeEditor extends JComboBox implements TableCellEditoras a ComboBox editor for JTable
    Please Help Me.

    Hi
    I am giving u a sample code which simulate the error
    * TestJTable.java
    * Created on August 5, 2008, 11:05 AM
    package TestJTable;
    import javax.swing.DefaultCellEditor;
    import javax.swing.table.TableColumn;
    * @author  yogi
    public class TestJTable extends javax.swing.JFrame {
        /** Creates new form TestJTable */
        public TestJTable() {
            initComponents();
            DefaultCellEditor ColumnEditor = new DefaultCellEditor(jComboBox1);
            ColumnEditor.setClickCountToStart(2);
            TableColumn column = jTable1.getColumnModel().getColumn(0);
            column.setCellEditor(ColumnEditor);       
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
        private void initComponents() {
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = new javax.swing.JTable();
            jComboBox1 = new javax.swing.JComboBox();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            getContentPane().setLayout(null);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null}
                new String [] {
                    "Title 1", "Title 2", "Title 3", "Title 4"
            jScrollPane1.setViewportView(jTable1);
            getContentPane().add(jScrollPane1);
            jScrollPane1.setBounds(10, 10, 340, 180);
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
            getContentPane().add(jComboBox1);
            jComboBox1.setBounds(180, 220, 120, 20);
            pack();
        }// </editor-fold>//GEN-END:initComponents
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    TestJTable TJTable = new TestJTable();
                    TJTable.setExtendedState(MAXIMIZED_BOTH);               
                    TJTable.setVisible(true);
        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable jTable1;
        // End of variables declaration//GEN-END:variables
    }Above code is generated by Netbeans IDE 6.0
    My promblem is that when you run the code the combobox JComboBox1 remains visible till i starts to edit the Table after once started editing it disappears.
    I want to avoid this
    thanks in advance

  • Problem with comboBox editor

    Hi experts,
    i am keeping a combobox renderer and editor in my JTable for 2 columns say 5th column and 7th column.
    In renderer no Problem.
    But while i am editing ,whenever i am choosing a perticular item from the drop down in the first row of table,it is affecting the remaining set of rows.,not all the rows also.
    for example,next 5 rows are getting the same selected value.
    next some 2 rows are getting affected.
    the below 2 class are my renderer and editor.public class ComboBoxRenderer extends JComboBox implements TableCellRenderer {
            public ComboBoxRenderer(String[] items) {
                            super(items);
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    if (isSelected) {
                    // Select the current value
                    setSelectedItem(value);
                    return this;
    }My ComboBox editor is public class ComboBoxEditor extends DefaultCellEditor {
            public ComboBoxEditor(String[] items) {
                   super(new JComboBox(items));
    }so i am using this render and editor in my swing screen by the following codeString strSP[] = {"P", "O", "H", " "};
    column5.setCellEditor(new ComboBoxEditor(strSP));
    column5.setCellRenderer(new ComboBoxRenderer(strSP));I am sure like the problem with my renderer and editoronly,but i am helpless.
    Please if someone help me to come out of this problem,it will be much helpful for me .
    thanks

    Hi,
    Thanks for u'r reply
    I tried in so many ways.
    I tried with u'r editor,and sun forum examples also.
    I brief what i want.
    I am having table with 3 column.
    The zeroth col, and the 2 col is a combo box.so i am rendering.
    when i choose a one from zeroth col combo Box ,the 2nd col ComboBox value has to change into YES
    when i choose a apart from one from zeroth col combo Box ,the 2nd col combo Box value has to change into NO.
    Here my Problem is
    When ever i am choosing the particular value from the 1st combo box,it is affecting the all the combobox values below(set of values,not all)..To solve that i kept the commented line in the renderer but it is creating the new problem.
    I am very seriously working to solve this problem,if any one suggest to solve this,it will be very much helpful to me.
    I am posting my code belowimport java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.TableModelEvent;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.*;
    public class TableComboBox extends JFrame implements TableModelListener
         public JTable table;
            DefaultTableModel model = null;
            JComboBox editor2 = null;
         public TableComboBox()
              Object[][] data = { {" ", "A" , " "}, {" ", "B", " "}, {" ", "C", " "}, {" ", "D", " "}, {" ", "E", " "}, {" ", "F", " "}, {" ", "G", " "}, {" ", "H", " "}  };
                    String[] columnNames = {"FIRST","SECOND", "THIRD" };
                    String[] column0Items = { "one", "two", "three", "four" };
                    String column2Items[] = {"YES","NO"};
              model = new DefaultTableModel(data, columnNames);
                    model.addTableModelListener(this);
              table = new JTable(model);
              //  Set the Zeroth column to use a combobox as its editor,renderer
                    table.getColumnModel().getColumn(0).setCellRenderer(new ComboBoxRenderer(column0Items));
              table.getColumnModel().getColumn(0).setCellEditor(new ComboBoxEditor(column0Items));
                    //  Set the second column to use a combobox as its editor,renderer
                    table.getColumnModel().getColumn(2).setCellRenderer(new ComboBoxRenderer(column2Items));
              table.getColumnModel().getColumn(2).setCellEditor(new ComboBoxEditor(column2Items));
                    JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
             public void tableChanged(TableModelEvent e) {
                    int row = e.getFirstRow();
                    int column = e.getColumn();
                    if(e.getType() == TableModelEvent.INSERT) {
                    if (e.getType() == TableModelEvent.UPDATE) {
                            if(table.getEditingRow() != table.getSelectedRow())
                                    ((DefaultCellEditor)table.getCellEditor()).cancelCellEditing();                      
                   if ( column == 0 ) {
                                    if(model.getValueAt(row, 0).equals("one")) {
                                            model.setValueAt("YES", row, 2);
                                    } else if(model.getValueAt(row, 0).equals("two")){
                                            model.setValueAt("NO", row, 2);
                                    } else if(model.getValueAt(row, 0) == "three"){
                                            model.setValueAt("NO", row, 2);
                                    } else if(model.getValueAt(row, 0) == "four"){
                                            model.setValueAt("NO", row, 2);
                           }else{
                                    //do nothing
         public static void main(String[] args)
              final TableComboBox frame = new TableComboBox();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
            class ComboBoxRenderer extends JComboBox implements TableCellRenderer {
                    String items[];
                    public ComboBoxRenderer(String[] items) {
                                    super(items);
                                    this.items = items;
                    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                                   if(isSelected){
                                            setSelectedItem(value.toString());
                                            return this;
                                    }/*else{
                                            setSelectedItem(items[0]));
                            return this;
            class ComboBoxEditor extends DefaultCellEditor {
                    public ComboBoxEditor(String[] items) {
                           super(new JComboBox(items));
            }

  • AutoComplete JComboBox As JTable cell editor

    Hello, when I try to use AutoComplete JComboBox as my JTable cell editor, I facing the following problem
    1) Exception thrown when show pop up. - Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
    2) Unable to capture enter key event.
    Here is my complete working code. With the same JComboBox class, I face no problem in adding it at JFrame. But when using it as JTable cell editor, I will have the mentioned problem.
    Any advice? Thanks
    import javax.swing.*;
    import javax.swing.JTable.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    * @author  yccheok
    public class NewJFrame extends javax.swing.JFrame {
        /** Creates new form NewJFrame */
        public NewJFrame() {
            initComponents();
                    /* Combo Box Added In JFrame. Work as expected. */
                    final JComboBox comboBox = new JComboBox();
                    comboBox.addItem("Snowboarding");
                    comboBox.addItem("Rowing");
                    comboBox.addItem("Chasing toddlers");   
                    comboBox.setEditable(true);
                    comboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
                       public void keyReleased(KeyEvent e) {
                           if(e.getKeyCode() == KeyEvent.VK_ENTER) {
                               System.out.println("is enter");
                               return;
                           System.out.println("typed");
                           comboBox.setSelectedIndex(0);
                           comboBox.showPopup();
                    getContentPane().add(comboBox, java.awt.BorderLayout.SOUTH);
        public JTable getMyTable() {
            return new JTable() {
                 Combo Box Added In JTable as cell editor. Didn't work as expected:
                 1. Exception thrown when show pop up.
                 2. Unable to capture enter key event.
                public TableCellEditor getCellEditor(int row, int column) {
                    final JComboBox comboBox = new JComboBox();
                    comboBox.addItem("Snowboarding");
                    comboBox.addItem("Rowing");
                    comboBox.addItem("Chasing toddlers");   
                    comboBox.setEditable(true);
                    comboBox.getEditor().getEditorComponent().addKeyListener(new KeyAdapter() {
                       public void keyReleased(KeyEvent e) {
                           if(e.getKeyCode() == KeyEvent.VK_ENTER) {
                               System.out.println("is enter");
                               return;
                           System.out.println("typed");
                           comboBox.setSelectedIndex(0);
                           comboBox.showPopup();
                    return new DefaultCellEditor(comboBox);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            jScrollPane1 = new javax.swing.JScrollPane();
            jTable1 = getMyTable();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jTable1.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null},
                    {null, null, null, null}
                new String [] {
                    "Title 1", "Title 2", "Title 3", "Title 4"
            jScrollPane1.setViewportView(jTable1);
            getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
            pack();
        }// </editor-fold>                       
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable jTable1;
        // End of variables declaration                  
    }

    You need to create a custom CellEditor which will prevent these problems from occurring. The explanation behind the problem and source code for the new editor can be found at Thomas Bierhance's site http://www.orbital-computer.de/JComboBox/. The description of the problem and the workaround are at the bottom of the page.

  • JTable cell editor popup

    Hi All
    I created a CalendarPanel, which contains a combobox for months and a spinner for year and grid of JLabels to display dates.
    And, a JTable with a cell which holds a date value. I created a cell editor with JSpinner to increment or decrement date by 1, which is practically not good. So I added a button top popup the calendar and user selects the date.
    Cell editor is a JPanel with a spinner and a small JButton. The click event of this button shows a Calendar (another JPanel) in which we can select the date.
    The spinner in the cell editor and the Calendar are linked to each other so that if user clicks on the spinner to change the date, that change reflects in the calendar also, and vice versa.
    I am able to popup the calendar on top of JTable at appropriate location (exactly below the cell) and when user selects the date it changes the value of spinner and vice versa.
    With this I have two problems.
    1. When user clicks on some other area of the calendar (except spinner) the calendar should automatically disappear. Right now when user double clicks on the date it disappears.
    2. In the calendar panel when I click on combo box to select the month or on the spinner to change the year - table cell is losing its focus and stopping the cell editing, means no link with calendar and the cell. But this is not happening with the label click (I guess this is because JLabels have no focus)
    How can I solve these 2.
    Thanks in advance.

    1. When user clicks on some other area of the calendar
    (except spinner) the calendar should automatically
    disappear. Right now when user double clicks on the
    date it disappears. Add a mouse listener to the other components that updates the calendar, the setVisible(false).
    2. In the calendar panel when I click on combo box to
    select the month or on the spinner to change the year
    - table cell is losing its focus and stopping the cell
    editing, means no link with calendar and the cell. But
    this is not happening with the label click (I guess
    this is because JLabels have no focus)
    Have your cell editor extend DefaultCellEditor. In the constructor, set the editorComponent to your new calendar component. Add a mouse listener (adapter) to the editorComponent - in mouseClicked, call stopCellEditing().

  • JTable  - ComboBox problem

    From using a tutorial from a website.. it places a JComboBox in first column the ComboBox elements are: "item1", "item2", "item3", all rows are given these values.
    How can I do it such that JComboBox have different values for each row?
    JTable table = new JTable();
        DefaultTableModel model = (DefaultTableModel)table.getModel();
        // Add some columns
        model.addColumn("A", new Object[]{"item1"});
        model.addColumn("B", new Object[]{"item2"});
        // These are the combobox values
        String[] values = new String[]{"item1", "item2", "item3"};
        // Set the combobox editor on the 1st visible column
        int vColIndex = 0;
        TableColumn col = table.getColumnModel().getColumn(vColIndex);
        col.setCellEditor(new MyComboBoxEditor(values));
        // If the cell should appear like a combobox in its
        // non-editing state, also set the combobox renderer
        col.setCellRenderer(new MyComboBoxRenderer(values));
        public class MyComboBoxRenderer extends JComboBox implements TableCellRenderer {
            public MyComboBoxRenderer(String[] items) {
                super(items);
            public Component getTableCellRendererComponent(JTable table, Object value,
                    boolean isSelected, boolean hasFocus, int row, int column) {
                if (isSelected) {
                    setForeground(table.getSelectionForeground());
                    super.setBackground(table.getSelectionBackground());
                } else {
                    setForeground(table.getForeground());
                    setBackground(table.getBackground());
                // Select the current value
                setSelectedItem(value);
                return this;
        public class MyComboBoxEditor extends DefaultCellEditor {
            public MyComboBoxEditor(String[] items) {
                super(new JComboBox(items));
        }

    thank you for informing me, i will be posting question on that, the solution is helpful...but not sufficient..
    For ref. the topic is:
    http://forum.java.sun.com/thread.jspa?threadID=606573

  • Tab transversal while using JTextArea as a JTable cell editor..

    I'm working on a project that will use a JTable with a JTextArea cell editor to create a chart for classroom scheduling. Searching on Google, I found a way to use a JTextArea as a cell editor and render the cell properly. However, when editing a cell, pressing the Tab key inserts a tab, rather than leaving the cell and going to the next one, as happens with just a regular JTable. In fact, none of the keyboard shortcuts that work on a JTable work once the JTextArea cell editor is used. Does anyone know of any way to resolve this? Below is some code I'm using to create a sample GUI, just to verify that I can do this. Another question is would it be easier to use a bunch of JLabels and JTextAreas, remove the padding from those JTextAreas, and try to allow for Tab transversals between stand-alone JTextAreas, rather than JTextAreas as JTable cell editors?
    Thanks!
    package edu.elon.table;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class GUI
         private JFrame frame;
         private String[] columnNames = {"Classroom", "8:00-9:10", "9:25-10:35",
              "10:50-12:00", "12:15-1:25", "1:40-2:50", "1:40-3:20 (MW)",
              "3:35-5:15 (MW)", "5:30-7:10 (MW)"};
         private Object[][] data = {columnNames,
              {"ALAM 201 (42)\nENG 110 LAB", "", "", "", "", "", "", "", ""},
              {"ALAM 202 (42)\nDP/DVD", "", "", "", "", "", "", "", ""},
              {"ALAM 203 (38)\nDP/DVD", "", "", "", "", "", "", "", ""},
              {"ALAM 205 (40)\n", "", "", "", "", "", "", "", ""},
              {"ALAM 206 (39)\nSINK, TV/VCR", "", "", "", "", "", "", "", ""},
              {"ALAM 207 (40+)\nDP/DVD", "", "", "", "", "", "", "", ""},
              {"ALAM 214 (38)\nTV/VCR", "", "", "", "", "", "", "", ""},
              {"ALAM 215 (42)\nTV/VCR", "", "", "", "", "", "", "", ""},
              {"ALAM 216 (42)\n", "", "", "", "", "", "", "", ""},
              {"ALAM 301 (40)\nTV/VCR", "", "", "", "", "", "", "", ""},
              {"ALAM 302 (38)\nDP/DVD", "", "", "", "", "", "", "", ""},
              {"ALAM 304 (35)\nFRENCH", "", "", "", "", "", "", "", ""},
              {"ALAM 314 (30)\nDP, PSY, COMPUTER ASSISTED", "", "", "", "", "", "",
              {"ALAM 315 (40)\nPC LAB, DP/DVD", "", "", "", "", "", "", "", ""}};
         private JTable table;
         public GUI()
              frame = new JFrame();
              table = new JTable(data, columnNames);
              table.setRowHeight(table.getRowHeight()*2);
              TableColumnModel cModel = table.getColumnModel();
              TextAreaRenderer renderer = new TextAreaRenderer();
              TextAreaEditor editor = new TextAreaEditor();
              for (int i = 0; i < cModel.getColumnCount(); i++)
                   cModel.getColumn(i).setCellRenderer(renderer);
                   cModel.getColumn(i).setCellEditor(editor);
              frame.setLayout(new GridLayout(1,0));
              frame.add(table);
              frame.pack();
              frame.setVisible(true);
    public static void main (String[] args)
    GUI gui = new gui();
    * Written by Dr. Heinz Kabutz, found through online newsletter via Google.
    class TextAreaRenderer extends JTextArea
    implements TableCellRenderer {
    private final DefaultTableCellRenderer adaptee =
    new DefaultTableCellRenderer();
    /** map from table to map of rows to map of column heights */
    private final Map cellSizes = new HashMap();
    public TextAreaRenderer() {
    setLineWrap(true);
    setWrapStyleWord(true);
    public Component getTableCellRendererComponent(//
    JTable table, Object obj, boolean isSelected,
    boolean hasFocus, int row, int column) {
    // set the colours, etc. using the standard for that platform
    adaptee.getTableCellRendererComponent(table, obj,
    isSelected, hasFocus, row, column);
    setForeground(adaptee.getForeground());
    setBackground(adaptee.getBackground());
    setBorder(adaptee.getBorder());
    setFont(adaptee.getFont());
    setText(adaptee.getText());
    // This line was very important to get it working with JDK1.4
    TableColumnModel columnModel = table.getColumnModel();
    setSize(columnModel.getColumn(column).getWidth(), 100000);
    int height_wanted = (int) getPreferredSize().getHeight();
    addSize(table, row, column, height_wanted);
    height_wanted = findTotalMaximumRowSize(table, row);
    if (height_wanted != table.getRowHeight(row)) {
    table.setRowHeight(row, height_wanted);
    return this;
    private void addSize(JTable table, int row, int column,
    int height) {
    Map rows = (Map) cellSizes.get(table);
    if (rows == null) {
    cellSizes.put(table, rows = new HashMap());
    Map rowheights = (Map) rows.get(new Integer(row));
    if (rowheights == null) {
    rows.put(new Integer(row), rowheights = new HashMap());
    rowheights.put(new Integer(column), new Integer(height));
    * Look through all columns and get the renderer. If it is
    * also a TextAreaRenderer, we look at the maximum height in
    * its hash table for this row.
    private int findTotalMaximumRowSize(JTable table, int row) {
    int maximum_height = 0;
    Enumeration columns = table.getColumnModel().getColumns();
    while (columns.hasMoreElements()) {
    TableColumn tc = (TableColumn) columns.nextElement();
    TableCellRenderer cellRenderer = tc.getCellRenderer();
    if (cellRenderer instanceof TextAreaRenderer) {
    TextAreaRenderer tar = (TextAreaRenderer) cellRenderer;
    maximum_height = Math.max(maximum_height,
    tar.findMaximumRowSize(table, row));
    return maximum_height;
    private int findMaximumRowSize(JTable table, int row) {
    Map rows = (Map) cellSizes.get(table);
    if (rows == null) return 0;
    Map rowheights = (Map) rows.get(new Integer(row));
    if (rowheights == null) return 0;
    int maximum_height = 0;
    for (Iterator it = rowheights.entrySet().iterator();
    it.hasNext();) {
    Map.Entry entry = (Map.Entry) it.next();
    int cellHeight = ((Integer) entry.getValue()).intValue();
    maximum_height = Math.max(maximum_height, cellHeight);
    return maximum_height;
    * Written by Dr. Heinz Kabutz, found through online newsletter via Google.
    class TextAreaEditor extends DefaultCellEditor
    public TextAreaEditor() {
         super(new JTextField());
    final JTextArea textArea = new JTextArea();
    textArea.setWrapStyleWord(true);
    textArea.setLineWrap(true);
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setBorder(null);
    editorComponent = scrollPane;
    delegate = new DefaultCellEditor.EditorDelegate() {
    public void setValue(Object value)
    textArea.setText((value != null) ? value.toString() : "");
    public Object getCellEditorValue()
    return textArea.getText();
    }

    Using the KeyEvent manager and playing around with the JTextArea, I was able to get a JTable using JTextAreas as the cell editors that worked very close to the way the regular JTable works. You have to hit Tab twice to shift focus to another cell, or hit Tab once and then an arrow key. Also, Alt-Enter will allow you to enter a cell for editing. All of the changes were made to the TextAreaEditor class, which should now read as follows:
    class TextAreaEditor extends DefaultCellEditor implements KeyListener
         private int lastKeyCode;
         public TextAreaEditor(final JTable table) {
              super(new JTextField());
              lastKeyCode = KeyEvent.CTRL_DOWN_MASK;
              final JTextArea textArea = new JTextArea();
              textArea.setWrapStyleWord(true);
              textArea.setLineWrap(true);
              textArea.addKeyListener(this);
              textArea.setFocusable(true);
              textArea.setFocusAccelerator((char) KeyEvent.VK_ENTER);
              JScrollPane scrollPane = new JScrollPane(textArea);
              scrollPane.setBorder(null);
              scrollPane.setFocusable(false);
              editorComponent = scrollPane;
              delegate = new DefaultCellEditor.EditorDelegate() {
                   public void setValue(Object value) {
                        textArea.setText((value != null) ? value.toString() : "");
                   public Object getCellEditorValue() {
                        return textArea.getText();
         public void keyTyped(KeyEvent ke)
              // TODO Auto-generated method stub
         public void keyPressed(KeyEvent ke)
              if (ke.getKeyCode() == KeyEvent.VK_TAB)
                   ke.consume();
                   KeyboardFocusManager.getCurrentKeyboardFocusManager()
                             .focusNextComponent();
                   return;
              if (ke.getKeyCode() == KeyEvent.VK_TAB && ke.isShiftDown())
                   ke.consume();
                   KeyboardFocusManager.getCurrentKeyboardFocusManager()
                             .focusPreviousComponent();
                   return;
              if ((lastKeyCode == KeyEvent.CTRL_DOWN_MASK) &&
                        (ke.getKeyCode() == KeyEvent.VK_ENTER))
                   ke.consume();
                   editorComponent.requestFocus();
              else
                   lastKeyCode = ke.getKeyCode();
         public void keyReleased(KeyEvent ke)
              // TODO Auto-generated method stub
         }

  • Custom JTable cell editor problem

    I have a custom JTable cell editor which is a JPanel with 2 JtextFields, One for a name, the other for a data value. My problem lies in when the the cell is selected and then the user start typing. The JTextfield outline shows up, but there is no carat. I can only edit the cell when I click the mouse in it again. I have my isCellEditable method set to only allow editing on 2 mouse clicks, but I did try it with just returning true and had the same problem. Please help.
    Code:
    class cellValue {
    String name;
    String data;
    Color nameColor;
    Color dataColor;
    Font font;
    public cellValue(String n, String d, Color nC, Color dC, Font ff){
    name = n;
    data = d;
    nameColor = nC;
    dataColor = dC;
    font = ff;
    } //end class
    public class TextFieldCellEditor extends JPanel implements TableCellRenderer, TableCellEditor{
    private EventListenerList listenerList = new EventListenerList();
    private ChangeEvent event = new ChangeEvent(this);
    private cellValue s;
    private int e_row=0;
    private int e_col=0;
    private JTextField ta;
    private JTextField tb;
    public TextFieldCellEditor() {
    setLayout(new GridBagLayout());
    ta = new JTextField();
    tb = new JTextField();
    tb.setHorizontalAlignment(SwingConstants.RIGHT);
    add(ta, new GridBagConstraints(0,0,1,1,0.6,0.0,java.awt.GridBagConstraints.WEST,java.awt.GridBagConstraints.BOTH,new Insets(0,1,0,0),0,0));
    add(new JLabel(" "),new GridBagConstraints(1,0,1,1,0.1,0.0,java.awt.GridBagConstraints.WEST,java.awt.GridBagConstraints.BOTH,new Insets(0,1,0,0),0,0));
    add(tb, new GridBagConstraints(2,0,1,1,0.3,0.0,java.awt.GridBagConstraints.EAST,java.awt.GridBagConstraints.BOTH,new Insets(0,1,0,0),0,0));
    } //end init
    public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected,
    boolean hasFocus,int row, int column) {
    s = (cellValue)value;
    e_row = row;
    e_col = column;
    ta.setText(s.name);
    tb.setText(s.data);
    ta.setFont(s.font);
    tb.setFont(s.font);
    ta.setForeground(s.nameColor);
    tb.setForeground(s.dataColor);
    setForeground(table.getForeground());
    setBackground(table.getBackground());
    ta.setBackground(table.getBackground());
    tb.setBackground(table.getBackground());
    ta.setCaretColor(Color.WHITE);
    tb.setCaretColor(Color.WHITE);
    return (JComponent)(this);
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    return (getTableCellRendererComponent(table, value,isSelected, true, row, column));
    public boolean isCellEditable(EventObject e) {
    if (e instanceof MouseEvent) {
    return ((MouseEvent)e).getClickCount() >= 2;
    } return true;
    // return true;
    public boolean shouldSelectCell(EventObject anEvent) {
    return (true);
    public void cancelCellEditing() {
    public boolean stopCellEditing() {
    fireEditingStopped();
    return (true);
    public Object getCellEditorValue() {
    return (ta.getText());
    public void addCellEditorListener(CellEditorListener l){
    try {
    SwingUtilities.invokeLater(
    new Runnable() {
    public void run() {requestFocus();}
    } catch (Exception e) {};
    listenerList.add(CellEditorListener.class, l);
    public void removeCellEditorListener(CellEditorListener l) {
    listenerList.remove(CellEditorListener.class, l);
    protected void fireEditingStopped(){
    Object[] listeners = listenerList.getListenerList();
    for (int i = listeners.length - 2; i >= 0; i -= 2)
    ((CellEditorListener)listeners[i+1]).editingStopped(event);
    protected void fireEditingCanceled() {
    Object[] listeners = listenerList.getListenerList();
    for (int i = listeners.length - 2; i >= 0; i -= 2)
    ((CellEditorListener)listeners[i+1]).editingCanceled(event);
    } //end class

    Thanks again for the repley.
    I tried removing the celleditorlistener and using the setSurrenderFocusOnKeystroke, but it did not work. The textfield is editable;
    I did change:
    public void addCellEditorListener(CellEditorListener l){
    try {
    SwingUtilities.invokeLater(
    new Runnable() {
    public void run() {ta.requestFocus();}
    } catch (Exception e) {};
    listenerList.add(CellEditorListener.class, l);
    }This allows the first textfield to request focus and this seems to work. But when I highlight a cell, then start typing, the first character I type puts me into the editor, but it is lost. Example:
    I type hello
    and get ello in the cell. Then when I press enter the input is excepted and the selection goes to the next cell, but I cannot move the Highlight cursor at all, seems locked. The only way I can continue to the next cell is to use the mouse.
    You said you had a cell editor working. Would you care to share as an example. This is killing me to get this to work properly.
    Thanks again
    Dave

  • Edit in external editor with lightroom adjustments issue LR5 and PS CC

    Since several days when I try (in Lightroom) 5 to edit an adjusted file (NEF, JPEG or TIFF) in Photoshop CC as external editor (with the option "edit a copy with lightroom adjustments") in many cases the adjustments ar not visible in photoshop CC, or only partial visible, and sometimes the file opens not at all. Removal of the preference files of LR 5 and PS CC and  a whole new installation of LR 5 didn't resolve the issue. I have a macbookPRO with Mac OS 10.8.5 and the most recent versions of LR 5 and PS CC. Has anyone experienced this problem and what can be a solution.

    I have no idea, but have you tried File / Catalog Settings/ General tab: Relaunch and Optimize. Relates to the database.

  • Using Rich Text Editor with a Custom Attribute

    Hello All,
    Can anyone please tell me as how can I use the Rich Text Editor with a Custom Attribute?
    I want to create a custom attribute based on text datatype, but when entering the value for this attribute in a Custom Item, portal shows a normal textarea. I want that the user should see the Richt Text Editor.
    Thanks for help.
    Regards

    Hi,
    Can you tell me what steps you are using to produce this, and which Portal version you are using. When I tried it, I wasn't able to reproduce it. Here are my steps:
    1) Created Custom Item Type, based on Text, under
    Page Groups > Shared Objects > Item Types
    2) Selected Three attributes (Description, Name, Publish Date). Note Text and Display Name were already selected
    3) In Add Item Wizard, configured list to allow for my
    custom item type selection.
    4) Then I was able to see the Rich Text Editor when editin
    my custom item type.
    Regards,
    J.

  • How to define the tab space in the PL/SQL editor with Oracle Forms 4.5?

    When I use the PL/SQL editor with Oracle Form Builder, I found the tab space is very long that affects my programs readability quite a lot. Then, I tried to use Textpad to type my program. It looks fine with Textpad. However, when i tried to 'cut and paste' my code back to the PL/SQL editor, all tab spaces (approx. 8-character) are detected and the program looks awful again ~~ Would any one help me to solve my mentioned problem?
    Thanks for any advices!

    In 4.5 you cannot change this. In Forms 5.0 and above there is a registry value DE_PREFS_TABSIZE which allows you to set a value for the tabsize.

  • Making Rich Text Editor with PHP in Dreamweaver  - Problem with CKEditor...

    Hi,
    I am developing a website in Dreamweaver and using the platform of PHP and MYSQL. I need to develop a Rich Text Editor just like the one I am typing at the moment. With my recent searches I have come across with CKEditor as one of the possibilities to add a Rich Text Editor to my website. I have seen older versions of CKEditor also known as FCKEditor which I believe unfortunatley is out of date and obsolete now (discontinued). I cannot find any of the downloads now from anywhere on the web.
    I can find FCKEditor tutorials with PHP,  but can not find CKEditor tutorials for PHP (when I try googling it, it always gives me FCKEditor page). Can anyone please help me and tell me if I can still make Rich Text Editor using CKEditor and PHP?
    If yes, please guide me how? Any tutorials or reading material will be very helpful.
    Regards,
    Bilal . Khan

    Yes, you absolutely can use CKEditor to create a rich text editor with PHP/MySQL.I have tried several editors and it's my choice.
    Here is a link to the documentation page:
    http://docs.cksource.com/
    CKFinder is also very good in conjunction with CKEditor. Although it costs $59/per website, it's better than the free alternatives.

  • SQL editor with tree view

    We are working on some extraordiary long SQL stored procedure. Due to the shear size and IF/ELSE nesting it is very tedious to understand the logic .
    What I am looking for is an SQL editor with tree view, where we can see IF/ ELSE, LOOP etc block as nodes. For example expand a node and see all blcoks of code within it.
    + IF block 1
    expand---
    -IF blcok 1
    +IF block 1.1
    +IF block 1.2
    further expand
    -IF blcok 1
    +IF block 1.1
    -IF block 1.2
    IF block 1.2.1

    Do some Google searches for a text editor that supports "folding".

  • Text editor with 15 lines

    Hi all,
    I have a requirement to create a text editor.
    I created a Text editor,but where i need only 15 lines to update into it .
    But it showing 22 lines and some times 30 lines .
    Anybody let me know how to update Text editor with 30 lines .
    Regards,
    Madhavi

    solved myself

  • Business Logic Editor with Complex Transasctions

    I'm starting to have some serious problems using the Business Logic Editor with reasonably large (but by no means huge) transactions. These transactions also have nested transaction calls down a few layers. The main symptoms are:
    1)  When opening the Link Editor on the first action it is somewhat sluggish. Opening the Link Editor on the last action can take over 60 seconds.
    2)  If adding a new Transaction Call action, selecting the called transaction in the Configure window doesn't work. The transaction can be selected OK, but the browse window will not close. It has to be cancelled. The Link Editor does not show the transaction's input, even though the Configure window will now show the selected transaction's path OK.
    3)  If the transaction is Saved after 2), that transaction will not open again in the Logic Editor, even after a reboot.
    Memory seems to be part of the formula. The above is on a notebook with 1Gb of RAM. On a dual core with 2 Gb, the problems are less, but not much. On a server with 8Gb, the symptoms disappear.
    Does anyone know if there is a recommended minimum system config for using the Logic Editor?
    What is actually happening when a transaction with nested Transaction Call actions is loaded in the Editor and for exection? I have many transactions that don't have the above problems, but they take a long time to open in the Logic Editor, and up to 1.5 seconds to load when executing the transaction (this is as per the F5 timings).
    Thanks,
    Bill

    Rick,
    These days I'm very careful about large embedded reference docs in my transactions. I actually go through the .trx files with notebook looking for any large chunks of that sort of XML and make sure they are eliminated.
    In the case of this transaction, by the time I get to the actual SQL query action (and remember it's a few layers of nested transaction calls down), it can't run the query anyway. The Query Template name in the configure window is blank. That and any params are set dynamically in Links at run time (the Query Template name actually comes from a config file). If I try Limit Rowcount or Yes when I close the configure window, it just gives an error because it has no idea what query template to run.
    Given this, the problem just doesn't seem related to fetching data. And how would this cause the Links window to take so long to open in the Logic Editor?
    Bill

Maybe you are looking for

  • Can't print from Win2000 to USB printer via Airport Extreme

    Background: I have an Epson Stylus Photo 820 printer connected by USB to an Airport Extreme base station. My iMac is connected to the base station via an ethernet cable. Using Bonjour for Windows 1.0.3, I've set up the Epson printer to print from Win

  • Problems with CLASSPATH in a executable jar file

    Hi there I'm having a problem that I don't know how to solve. My generalq uestion is: "Why isn't my CLASSPATH (java.class.path) forwarded into ar unnable class inside a jar file?" The situation is: I have made a runnable jar file containing an ant bu

  • Onekey & Partitioning - IdeaCentre K210 - 53134BU

    Hi, I Partitioned the (BIG) K210 "C" Drive into a "C" Drive for Vista and Onekey Rescue & Recovery, a "D" Drive which I use to install programs and apps, an "E" Drive where I keep the data files and a "F" Drive for photos. My question is, if I ever n

  • Apple tv graphics bad

    I'm having trouble with the cover art and photos being streamed from my iMac to the Apple TV (2).  It's obvioulsy lo-res compared to the native art on the atv like previews and other graphics.  I'm up to date with software on both machines and can't

  • Dead Video Ipod

    Help.. My video ipod is only a month old.. and it just died.. its not on hold ,the battery was fine.. it wasn't dropped. I tried recharging with the wall unit and USB port.. the chargers work fine since I tried them both with my nano and mini.. this