Search Results

Search found 5 results on 1 pages for 'tablecelleditor'.

Page 1/1 | 1 

  • What could I add to this code to allow the cell height to dynamically change as I edit the JTextArea

    - by Dr. Plaguey
    The derived classes I am using public class TextAreaRenderer extends JTextArea implements TableCellRenderer { public TextAreaRenderer() { setLineWrap(true); setWrapStyleWord(true); } public Component getTableCellRendererComponent(JTable jTable, Object obj, boolean isSelected, boolean hasFocus, int row, int column) { setText((String)obj); int height_wanted = (int)getPreferredSize().getHeight() + 10; if (height_wanted != rootJTable.getRowHeight(row)) rootJTable.setRowHeight(row, height_wanted); return this; } } class TextEditor extends AbstractCellEditor implements TableCellEditor { protected JTextArea ta; String txt; public TextEditor() { ta = new JTextArea(); } //Implement the one CellEditor method that AbstractCellEditor doesn't. public Object getCellEditorValue() { return ta.getText(); } // Implement the one method defined by TableCellEditor. public Component getTableCellEditorComponent(javax.swing.JTable table, Object value,boolean isSelected, int row, int column) { txt = value.toString(); ta.setText(txt); ta.setLineWrap(true); return new JScrollPane(ta); } public boolean isCellEditable(EventObject anEvent) { return true; } } Set column renderer and editor rootJTable.getColumnModel().getColumn(1).setCellRenderer(new TextAreaRenderer()); rootJTable.getColumnModel().getColumn(1).setCellEditor(new TextEditor());

    Read the article

  • Please help me to allow my `JTable` to search the text even the table is in editable mode on key-press

    - by Ashish Pancholi
    If user starts pressing keys using keyboards then JTable is supposed to be searched the matching text for him and if user double clicks on cell then Table should allow him to edit the text. And the issue is - Table is only searching text when the table is in non-editable mode and if Table is editable and user starts typing the text-using keyboard, cell is allowing him to edit the cell rather then search. Mr mKorbel has just solved my issue to allow edit only if double click on Table cell. Please help me to allow my JTable to search the text even the table is in editable mode on key-press.

    Read the article

  • Swing: Multiple CellEditors for a column

    - by Luhar
    Hi, In my JTable, I have two editable numeric columns. The editor for both columns extends AbstractCellEditor and uses a JFormattedTextField as an the editing component. The problem is that the format for input depends on the value of another column in the row. If condition X is met, the number of fraction digits should be Y, otherwise they should be Y+2. I attempted to override the getTableCellEditor(..) method to associate a TableCellEditor per row. See this example. However, since I have two editable columns, sharing a single TableCellEditor object per row gives some very odd results. I don't think this is an appropriate solution. Any ideas on how to approach this would be much appreciated! Thank you!

    Read the article

  • Creating a table with an initial element selected

    - by Tony
    I want to create a table which displays in each row a set of data, in addition to a radio button for possible selection. This can be achieved easily by using a simple table model class which extends the DefaultTableModel and a cell renderer and editor class which implements the TableCellRenderer and TableCellEditor interfaces respectively. What I really couldn't manage to do is to make the table to display initially one of the elements (rows) initially selected. It seems straightforward but it isn't...does anybody have a clue about it?

    Read the article

  • JTextField vs JComboBox behaviour in JTable

    - by Ash
    Okay, this is a hard one to explain but I'll try my best. I have a JTextField and a JComboBox in a JTable, whose getCellEditor method has been overriden as follows: public TableCellEditor getCellEditor( int row, int column ) { if ( column == 3 ) { // m_table is the JTable if ( m_table.getSelectedRowCount() == 1 ) { JComboBox choices = new JComboBox(); choices.setEditable( true ); choices.addItem( new String( "item 1" ) ); return new DefaultCellEditor( choices ); } return super.getCellEditor( row, column ); } Here are the behavioral differences (NOTE that from this point on, when I say JTextField or JComboBox, I mean the CELL in the JTable containing either component): When I click once on a JTextField, the cell is highlighted. Double clicking brings up the caret and I can input text. Whereas, with a JComboBox, single clicking brings up the caret to input text, as well as the combo drop down button. When I tab or use the arrow keys to navigate to a JTextField and then start typing, the characters I type automatically get entered into the cell. Whereas, when I navigate to a JComboBox the same way and then start typing, nothing happens apart from the combo drop down button appearing. None of the characters I type get entered unless I hit F2 first. So here's my question: What do I need to do have JComboBoxes behave exactly like JTextFields in the two instances described above? Please do not ask why I'm doing what I'm doing or suggest alternatives (it's the way it is and I need to do it this way) and yes, I've read the API for all components in question....the problem is, it's a swing API. Thanks in advance, Ash

    Read the article

1