JTable in a JTree

Can we have a JTable as a node of a JTree? Can anyone help with a code sample(if possible)?
Thanks in advance...

here's an example that show a tree with multiline..which is simliar to display a tree..instead of a JTextArea, you're would be a JscrollPane or a JTable alone.
http://www.codeguru.com/java/articles/141.shtml

Similar Messages

  • Editable jtable inside a jtree

    I want to create an editable jtable inside a jtree. can anyone show me how to do it? thank you.

    I want to create an editable jtable inside a jtree. can anyone show me how to do it? thank you.

  • Can we use JTable in a JTree?

    Hi Actually this is my first mail to this forum.
    I want to use a tables embedded in a tree . You can see such format in VB's Properties sheet's "Categorized" tab. Has anyone tried doing such format. Or anyone knows if it is possible to do it in Jtrees. If yes then how?
    Anybody knows? Pls mail back.
    Regards,
    Amit.

    Hi,
    Thanks for the reply. This will definately serve my purpose, but i cannot compromise on the GUI. But, Is there a way by which I can have table on the click of a tree node and not JTree as a renderer for the cells in a JTable.
    Pls mail back.
    Regards,
    Amit

  • Expand JTree using

    hi there,
    I have a JTree with DefaultMutableTreeNode as nodes each node represent a string.
    I have to ways to watch my data JTable and and JTree both are visible, I need to sync between them.
    sync the JTable to the JTree was easy, but now I don't have a clue how to sync the JTree to the JTable.
    both contain string as data.
    cause my app is kind of a Virtual HD, I display on the JTree and the JTable my files and directories.
    my intuition was to pass the current path to the JTree but I don't know how to create a TreePath to the needed node
    thank you

    Convert your node path to a TreePath and call expandPath.

  • Widgets Hierarchy.

    Hello,
    I'm building a JTree that uses a custom renderer. This renderer creates a number of other widgets to display a node: a JPanel, a button, a JTable, ... The tree is displayed as usual in a JScrollPane contained in a JFrame. Everything is displayed as spected.
    But if I try to go down the wiget hierarchy from the JFrame using the getComponents method from Container I cannot find the components created by the renderer. The only child of the JTree happens to be just one CellRenderPanel that has no components itself.
    The question is where are those components and how can I access them???
    Thanks a lot for your help.
    (Actually I'm trying to build a JTree which nodes can be expanded. So each node includes a button to hide/show details. I want to selected the display mode without entering in edition mode by clicking on the button. Edition mode is activated by double click. )

    Because the components aren't added, they're rendering delegates.
    Read the "How to use..." links from the API docs for JTable, JList and JTree to see how it works.

  • How to set and reset a file as readonly and hidden

    Hi all
    I am trying to produce the explorer as it is in windows. I am using Jtable instead of JTree. I want to show properties for each and every folder or file. While showing properies i want the user to set the file as readonly and sometime he doesn't want to. How to do it?
    I have used the option setReadOnly in the FIle class for setting but i dont know how to reset to not read only.
    Can someone produce code for Jtable explorer with all features.
    Lakshmi

    Search for exporting in the help file
    Not all for PProCC, but The PPro/Encore tutorial list in message #3 http://forums.adobe.com/message/2276578 may also help, with more help in message #5
    PS - rendering is the process of creating temporary files to aid in timeline playback, while exporting creates new files

  • JTreeTable rendering problems

    Hi all!
    I have used some clesses to create a JTable containing a JTree, basing on the example in the sun's site. The costructor is:
    JFrame frame = new JFrame("TITLE");
    JTreeTable table = createTable(); //Creates the treetable
    JScrollPane scrollPane = new JScrollPane(table); //it puts the newly created table in a scrollPane
    frame.getContentPane().add(scrollPane,BorderLayout.CENTER);
    frame.pack();
    frame.show();
    I have the following problems:
    1. If I have not many nodes in the tree, I have a bad renderer effect: the table doesn't fit the whole window but just the upper part of that, at the bottom it's all gray (the JFrame color, I think).Even if I set the JFrame background color to white, I still have that problem.
    2. If I don't add the table to the scrollbar, I can't see the headers, but I don't have the problem of the gray panel.
    Does anyone know how I can work out this? Has anybody examples of JTreeTables that don't have this rendering problem (with the table fitting the whole window even though they don't have many nodes)?
    Feedbacks are welcome, this is really showstopper for me...
    Thanks a lot!

    Hi there.
    Try setting the viewport color of your scrollpane. I don't have my API's on hand but you go something like myScrollPane.getViewport().setBackgroundColor(Color.white);
    How does that go for you?
    Cheers,
    Rachel

  • Help with TreeCellRenderer

    I am trying to create a JTree node with a JTable. I see only one line of data from JTable/JTables at the JTree node. What can I change so that it displays the whole JTable.
    And I don't see the default tree node Icons too atall folder like Icon if leaf nodes are there and dot like Icon if the node is a leaf. I see only the JTables for each node. What can I change so that I can see the Icons too.
    I have the following in the createnode() method.
    public void createNodes() {
    DefaultMutableTreeNode[] nodes = new DefaultMutableTreeNode[5];
    nodes[0] = new DefaultMutableTreeNode(table1);
    nodes[1] = new DefaultMutableTreeNode(table2);
    nodes[2] = new DefaultMutableTreeNode(table3);
    nodes[0].add(nodes[1]);
    nodes[0].add(nodes[2]);
    jTree1 = new JTree(nodes[0]);
    jTree1.setCellRenderer(new NodeRenderer());
    I have the following in the NodeRenderer
    public class NodeRenderer implements TreeCellRenderer {
    private JTable myTable;
    private JComponent renderer;
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    if((value instanceof DefaultMutableTreeNode)){
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    renderer = (JComponent)node.getUserObject();
    return renderer;
    Thanks.

    rxyz, i think you missed the point here, those icons are part of cellrenderer. so, if you want to see them, put them there. defaultTreeCellRenderer extends from JLabel and those icons are set with setIcon. now that you are using some JComponent(what ever it is) for rendering, it is up to you to put those icons there. so, my idea would be use a custom component where you can have an icon on lefthandside and JTable(may be flowlayout with some insets should do the trick) on right hand side,and render the tree with that component.

  • Need to add checkbox to JTreeTables..HELP plz

    hello everybody,
    I am having problems adding a checkbox to a JTreeTable example from sun .
    i also have a woriking checkbox Jtree class and it is working fine, i tried to add jtable to the jtree and i couldnt.
    can anybody help me, either how ti add a checkbox to a JTreeTable or how to add a JTable to a JCheckBoxTree.
    thanks lots.

    http://forum.java.sun.com/thread.jspa?threadID=461659&messageID=4024652#4024652

  • Origin of a Drag Operation

    I have a JTable and a JTree which are both Drag and Drop enabled. When moving items from table cell to table cell I want to do different processing than moving items from the tree to the table. Is there anyway to determine the origin of the Drag operation? I tried the getSource() method for the event, but it returns a DropTargetDropEvent and not the Component where the Drag originated.
    Thanks,
    Jeremy

    Have you tried getting the class type (instanceof) of the transfered object?
    Maybe they are different for tree and table.
    Or if its a DragSourceContext object, you could get the originating component using the getComponent() method.
    Object sourceObj = dropTargetDropEvent.getTransferable().getTransferData( supportedFlavors[0] );
    System.out.println("Type is: "+sourceObj.getClass().getName());
    if (sourceObj instanceof DragSourceContext)
      DragSourceContext dsc = (DragSourceContext)sourceObj;
      // at least the source component of the transfered object should be different for tree and table...
      Component sourceComponent = dsc.getComponent();
    }

  • How to put vertical Scroll Bar on the LEFT side of a VBox?

    The default is on the RIGHT side. It seems no easy solution on this question.

    Hi Darren,
    Thanks for your reply. I've narrowed the problem down to this strange behavior only happening when the viewport component is a tree-table (a JTable with a JTree for a column renderer). The tree-table works okay in JDK 1.3, but not in JDK 1.4. When I remove the JTree column renderer, the table draws correctly, but without the tree. It looks like the viewport position is being set wrong somewhere.
    When a column is resized, an AdjustmentEvent is created. So that's why resizing the column looked like it had the same effect as the horizontal scroll bar.
    If you're interested, then I will be happy to let you know how I fixed it, if I can.
    The complete code that creates the scroll pane with the vertical scroll bar on the left is below. There's too much code to post the JTree column renderer.
    Thank you,
    Don
    m_leftScrollPane = new JScrollPane(m_sourceTable,
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    m_leftScrollPane.setComponentOrientation
    (ComponentOrientation.RIGHT_TO_LEFT);

  • One model for JTree and JTable

    Hi.
    Is it possible for a JTree and a JTable to share one model?
    Thank you

    Hope u r not using Comonent TreeTable
    If u have Tree & Table different components, just want to have a common model then u can try this,
    It is nothing but default implementation given in DefaultTableModel
    public class MyTreeTableModel extends DefaultTreeModel implements TableModel, Serializable {
    protected Vector dataVector;
    /** List of listeners */
    protected EventListenerList listenerList = new EventListenerList();
    /** The <code>Vector</code> of column identifiers. */
    protected Vector columnIdentifiers;
    public MyTreeTableModel(TreeNode root) {
    this(root, false);
    // constructor for TreeModel only
    public MyTreeTableModel(TreeNode root, boolean asksAllowsChildren) {
    super(root, asksAllowsChildren);
    // constructor for TableModel only
    public MyTreeTableModel() {
    this(0, 0);
    private static Vector newVector(int size) {
    Vector v = new Vector(size);
    v.setSize(size);
    return v;
    // constructor for TableModel only
    public MyTreeTableModel(int rowCount, int columnCount) {
    this(newVector(columnCount), rowCount);
    // constructor for TableModel only
    public MyTreeTableModel(Vector columnNames, int rowCount) {
    super(null);
    setDataVector(newVector(rowCount), columnNames);
    // constructor for TableModel only
    public MyTreeTableModel(Object[] columnNames, int rowCount) {
    this(convertToVector(columnNames), rowCount);
    // constructor for TableModel only
    public MyTreeTableModel(Vector data, Vector columnNames) {
    super(null);
    setDataVector(data, columnNames);
    // constructor for TableModel only
    public MyTreeTableModel(Object[][] data, Object[] columnNames) {
    super(null);
    setDataVector(data, columnNames);
    * Returns a default name for the column using spreadsheet conventions:
    * A, B, C, ... Z, AA, AB, etc. If <code>column</code> cannot be found,
    * returns an empty string.
    * @param column the column being queried
    * @return a string containing the default name of <code>column</code>
    private String getDefaultColumnName(int column) {
    String result = "";
    for (; column >= 0; column = column / 26 - 1) {
    result = (char)((char)(column%26)+'A') + result;
    return result;
    * Returns a column given its name.
    * Implementation is naive so this should be overridden if
    * this method is to be called often. This method is not
    * in the <code>TableModel</code> interface and is not used by the
    * <code>JTable</code>.
    * @param columnName string containing name of column to be located
    * @return the column with <code>columnName</code>, or -1 if not found
    public int findColumn(String columnName) {
    for (int i = 0; i < getColumnCount(); i++) {
    if (columnName.equals(getColumnName(i))) {
    return i;
    return -1;
    * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.
    * @param columnIndex the column being queried
    * @return the Object.class
    public Class getColumnClass(int columnIndex) {
    return Object.class;
    // Managing Listeners
    * Adds a listener to the list that's notified each time a change
    * to the data model occurs.
    * @param     l          the TableModelListener
    public void addTableModelListener(TableModelListener l) {
    listenerList.add(TableModelListener.class, l);
    * Removes a listener from the list that's notified each time a
    * change to the data model occurs.
    * @param     l          the TableModelListener
    public void removeTableModelListener(TableModelListener l) {
    listenerList.remove(TableModelListener.class, l);
    * Returns an array of all the table model listeners
    * registered on this model.
    * @return all of this model's <code>TableModelListener</code>s
    * or an empty
    * array if no table model listeners are currently registered
    public TableModelListener[] getTableModelListeners() {
    return (TableModelListener[])listenerList.getListeners(
    TableModelListener.class);
    // Fire methods
    * Notifies all listeners that all cell values in the table's
    * rows may have changed. The number of rows may also have changed
    * and the <code>JTable</code> should redraw the
    * table from scratch. The structure of the table (as in the order of the
    * columns) is assumed to be the same.
    public void fireTableDataChanged() {
    fireTableChanged(new TableModelEvent(this));
    * Notifies all listeners that the table's structure has changed.
    * The number of columns in the table, and the names and types of
    * the new columns may be different from the previous state.
    * If the <code>JTable</code> receives this event and its
    * <code>autoCreateColumnsFromModel</code>
    * flag is set it discards any table columns that it had and reallocates
    * default columns in the order they appear in the model. This is the
    * same as calling <code>setModel(TableModel)</code> on the
    * <code>JTable</code>.
    public void fireTableStructureChanged() {
    fireTableChanged(new TableModelEvent(this, TableModelEvent.HEADER_ROW));
    * Notifies all listeners that rows in the range
    * <code>[firstRow, lastRow]</code>, inclusive, have been inserted.
    * @param firstRow the first row
    * @param lastRow the last row
    public void fireTableRowsInserted(int firstRow, int lastRow) {
    fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
    TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
    * Notifies all listeners that rows in the range
    * <code>[firstRow, lastRow]</code>, inclusive, have been updated.
    * @param firstRow the first row
    * @param lastRow the last row
    public void fireTableRowsUpdated(int firstRow, int lastRow) {
    fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
    TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE));
    * Notifies all listeners that rows in the range
    * <code>[firstRow, lastRow]</code>, inclusive, have been deleted.
    * @param firstRow the first row
    * @param lastRow the last row
    public void fireTableRowsDeleted(int firstRow, int lastRow) {
    fireTableChanged(new TableModelEvent(this, firstRow, lastRow,
    TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE));
    * Notifies all listeners that the value of the cell at
    * <code>[row, column]</code> has been updated.
    * @param row row of cell which has been updated
    * @param column column of cell which has been updated
    public void fireTableCellUpdated(int row, int column) {
    fireTableChanged(new TableModelEvent(this, row, row, column));
    * Forwards the given notification event to all
    * <code>TableModelListeners</code> that registered
    * themselves as listeners for this table model.
    * @param e the event to be forwarded
    public void fireTableChanged(TableModelEvent e) {
    // Guaranteed to return a non-null array
    Object[] listeners = listenerList.getListenerList();
    // Process the listeners last to first, notifying
    // those that are interested in this event
    for (int i = listeners.length-2; i>=0; i-=2) {
    if (listeners==TableModelListener.class) {
    ((TableModelListener)listeners[i+1]).tableChanged(e);
    * Returns an array of all the objects currently registered
    * as <code><em>Foo</em>Listener</code>s
    * upon this <code>AbstractTableModel</code>.
    * <code><em>Foo</em>Listener</code>s are registered using the
    * <code>add<em>Foo</em>Listener</code> method.
    * <p>
    * You can specify the <code>listenerType</code> argument
    * with a class literal,
    * such as
    * <code><em>Foo</em>Listener.class</code>.
    * For example, you can query a
    * model <code>m</code>
    * for its table model listeners with the following code:
    * <pre>TableModelListener[] tmls = (TableModelListener[])(m.getListeners(TableModelListener.class));</pre>
    * If no such listeners exist, this method returns an empty array.
    * @param listenerType the type of listeners requested; this parameter
    * should specify an interface that descends from
    * <code>java.util.EventListener</code>
    * @return an array of all objects registered as
    * <code><em>Foo</em>Listener</code>s on this component,
    * or an empty array if no such
    * listeners have been added
    * @exception ClassCastException if <code>listenerType</code>
    * doesn't specify a class or interface that implements
    * <code>java.util.EventListener</code>
    public EventListener[] getListeners(Class listenerType) {
    return listenerList.getListeners(listenerType);
    * Returns the <code>Vector</code> of <code>Vectors</code>
    * that contains the table's
    * data values. The vectors contained in the outer vector are
    * each a single row of values. In other words, to get to the cell
    * at row 1, column 5: <p>
    * <code>((Vector)getDataVector().elementAt(1)).elementAt(5);</code><p>
    * @return the vector of vectors containing the tables data values
    public Vector getDataVector() {
    return dataVector;
    private static Vector nonNullVector(Vector v) {
    return (v != null) ? v : new Vector();
    * Replaces the current <code>dataVector</code> instance variable
    * with the new Vector of rows, <code>dataVector</code>.
    * <code>columnIdentifiers</code> are the names of the new
    * columns. The first name in <code>columnIdentifiers</code> is
    * mapped to column 0 in <code>dataVector</code>. Each row in
    * <code>dataVector</code> is adjusted to match the number of
    * columns in <code>columnIdentifiers</code>
    * either by truncating the <code>Vector</code> if it is too long,
    * or adding <code>null</code> values if it is too short.
    * <p>Note that passing in a <code>null</code> value for
    * <code>dataVector</code> results in unspecified behavior,
    * an possibly an exception.
    * @param dataVector the new data vector
    * @param columnIdentifiers the names of the columns
    public void setDataVector(Vector dataVector, Vector columnIdentifiers) {
    this.dataVector = nonNullVector(dataVector);
    this.columnIdentifiers = nonNullVector(columnIdentifiers);
    justifyRows(0, getRowCount());
    fireTableStructureChanged();
    * Replaces the value in the <code>dataVector</code> instance
    * variable with the values in the array <code>dataVector</code>.
    * The first index in the <code>Object[][]</code>
    * array is the row index and the second is the column index.
    * <code>columnIdentifiers</code> are the names of the new columns.
    * @param dataVector          the new data vector
    * @param columnIdentifiers     the names of the columns
    public void setDataVector(Object[][] dataVector, Object[] columnIdentifiers) {
    setDataVector(convertToVector(dataVector), convertToVector(columnIdentifiers));
    * Equivalent to <code>fireTableChanged</code>.
    * @param event the change event
    public void newDataAvailable(TableModelEvent event) {
    fireTableChanged(event);
    // Manipulating rows
    private void justifyRows(int from, int to) {
    // Sometimes the MyTreeTableModel is subclassed
    // instead of the AbstractTableModel by mistake.
    // Set the number of rows for the case when getRowCount
    // is overridden.
    dataVector.setSize(getRowCount());
    for (int i = from; i < to; i++) {
    if (dataVector.elementAt(i) == null) {
    dataVector.setElementAt(new Vector(), i);
    ((Vector)dataVector.elementAt(i)).setSize(getColumnCount());
    * Ensures that the new rows have the correct number of columns.
    * This is accomplished by using the <code>setSize</code> method in
    * <code>Vector</code> which truncates vectors
    * which are too long, and appends <code>null</code>s if they
    * are too short.
    * This method also sends out a <code>tableChanged</code>
    * notification message to all the listeners.
    * @param e this <code>TableModelEvent</code> describes
    * where the rows were added.
    *                    If <code>null</code> it assumes
    * all the rows were newly added
    public void newRowsAdded(TableModelEvent e) {
    justifyRows(e.getFirstRow(), e.getLastRow() + 1);
    fireTableChanged(e);
    * Equivalent to <code>fireTableChanged</code>.
    * @param event the change event
    public void rowsRemoved(TableModelEvent event) {
    fireTableChanged(event);
    * Obsolete as of Java 2 platform v1.3. Please use <code>setRowCount</code> instead.
    * Sets the number of rows in the model. If the new size is greater
    * than the current size, new rows are added to the end of the model
    * If the new size is less than the current size, all
    * rows at index <code>rowCount</code> and greater are discarded. <p>
    * @param rowCount the new number of rows
    public void setNumRows(int rowCount) {
    int old = getRowCount();
    if (old == rowCount) {
    return;
    dataVector.setSize(rowCount);
    if (rowCount <= old) {
    fireTableRowsDeleted(rowCount, old-1);
    else {
    justifyRows(old, rowCount);
    fireTableRowsInserted(old, rowCount-1);
    * Sets the number of rows in the model. If the new size is greater
    * than the current size, new rows are added to the end of the model
    * If the new size is less than the current size, all
    * rows at index <code>rowCount</code> and greater are discarded. <p>
    public void setRowCount(int rowCount) {
    setNumRows(rowCount);
    * Adds a row to the end of the model. The new row will contain
    * <code>null</code> values unless <code>rowData</code> is specified.
    * Notification of the row being added will be generated.
    * @param rowData optional data of the row being added
    public void addRow(Vector rowData) {
    insertRow(getRowCount(), rowData);
    * Adds a row to the end of the model. The new row will contain
    * <code>null</code> values unless <code>rowData</code> is specified.
    * Notification of the row being added will be generated.
    * @param rowData optional data of the row being added
    public void addRow(Object[] rowData) {
    addRow(convertToVector(rowData));
    * Inserts a row at <code>row</code> in the model. The new row
    * will contain <code>null</code> values unless <code>rowData</code>
    * is specified. Notification of the row being added will be generated.
    * @param row the row index of the row to be inserted
    * @param rowData optional data of the row being added
    * @exception ArrayIndexOutOfBoundsException if the row was invalid
    public void insertRow(int row, Vector rowData) {
    dataVector.insertElementAt(rowData, row);
    justifyRows(row, row+1);
    fireTableRowsInserted(row, row);
    * Inserts a row at <code>row</code> in the model. The new row
    * will contain <code>null</code> values unless <code>rowData</code>
    * is specified. Notification of the row being added will be generated.
    * @param row the row index of the row to be inserted
    * @param rowData optional data of the row being added
    * @exception ArrayIndexOutOfBoundsException if the row was invalid
    public void insertRow(int row, Object[] rowData) {
    insertRow(row, convertToVector(rowData));
    private static int gcd(int i, int j) {
    return (j == 0) ? i : gcd(j, i%j);
    private static void rotate(Vector v, int a, int b, int shift) {
    int size = b - a;
    int r = size - shift;
    int g = gcd(size, r);
    for(int i = 0; i < g; i++) {
    int to = i;
    Object tmp = v.elementAt(a + to);
    for(int from = (to + r) % size; from != i; from = (to + r) % size) {
    v.setElementAt(v.elementAt(a + from), a + to);
    to = from;
    v.setElementAt(tmp, a + to);
    * Moves one or more rows from the inlcusive range <code>start</code> to
    * <code>end</code> to the <code>to</code> position in the model.
    * After the move, the row that was at index <code>start</code>
    * will be at index <code>to</code>.
    * This method will send a <code>tableChanged</code> notification
    * message to all the listeners. <p>
    * <pre>
    * Examples of moves:
    * <p>
    * 1. moveRow(1,3,5);
    * a|B|C|D|e|f|g|h|i|j|k - before
    * a|e|f|g|h|B|C|D|i|j|k - after
    * <p>
    * 2. moveRow(6,7,1);
    * a|b|c|d|e|f|G|H|i|j|k - before
    * a|G|H|b|c|d|e|f|i|j|k - after
    * <p>
    * </pre>
    * @param start the starting row index to be moved
    * @param end the ending row index to be moved
    * @param to the destination of the rows to be moved
    * @exception ArrayIndexOutOfBoundsException if any of the elements
    * would be moved out of the table's range
    public void moveRow(int start, int end, int to) {
    int shift = to - start;
    int first, last;
    if (shift < 0) {
    first = to;
    last = end;
    else {
    first = start;
    last = to + end - start;
    rotate(dataVector, first, last + 1, shift);
    fireTableRowsUpdated(first, last);
    * Removes the row at <code>row</code> from the model. Notification
    * of the row being removed will be sent to all the listeners.
    * @param row the row index of the row to be removed
    * @exception ArrayIndexOutOfBoundsException if the row was invalid
    public void removeRow(int row) {
    dataVector.removeElementAt(row);
    fireTableRowsDeleted(row, row);
    // Manipulating columns
    * Replaces the column identifiers in the model. If the number of
    * <code>newIdentifier</code>s is greater than the current number
    * of columns, new columns are added to the end of each row in the model.
    * If the number of <code>newIdentifier</code>s is less than the current
    * number of columns, all the extra columns at the end of a row are
    * discarded. <p>
    * @param newIdentifiers vector of column identifiers. If
    *                    <code>null</code>, set the model
    * to zero columns
    public void setColumnIdentifiers(Vector columnIdentifiers) {
    setDataVector(dataVector, columnIdentifiers);
    * Replaces the column identifiers in the model. If the number of
    * <code>newIdentifier</code>s is greater than the current number
    * of columns, new columns are added to the end of each row in the model.
    * If the number of <code>newIdentifier</code>s is less than the current
    * number of columns, all the extra columns at the end of a row are
    * discarded. <p>
    * @param newIdentifiers array of column identifiers.
    *                    If <code>null</code>, set
    * the model to zero columns
    public void setColumnIdentifiers(Object[] newIdentifiers) {
    setColumnIdentifiers(convertToVector(newIdentifiers));
    * Sets the number of columns in the model. If the new size is greater
    * than the current size, new columns are added to the end of the model
    * with <code>null</code> cell values.
    * If the new size is less than the current size, all columns at index
    * <code>columnCount</code> and greater are discarded.
    * @param columnCount the new number of columns in the model
    public void setColumnCount(int columnCount) {
    columnIdentifiers.setSize(columnCount);
    justifyRows(0, getRowCount());
    fireTableStructureChanged();
    * Adds a column to the model. The new column will have the
    * identifier <code>columnName</code>, which may be null. This method
    * will send a
    * <code>tableChanged</code> notification message to all the listeners.
    * This method is a cover for <code>addColumn(Object, Vector)</code> which
    * uses <code>null</code> as the data vector.
    * @param columnName the identifier of the column being added
    public void addColumn(Object columnName) {
    addColumn(columnName, (Vector)null);
    * Adds a column to the model. The new column will have the
    * identifier <code>columnName</code>, which may be null.
    * <code>columnData</code> is the
    * optional vector of data for the column. If it is <code>null</code>
    * the column is filled with <code>null</code> values. Otherwise,
    * the new data will be added to model starting with the first
    * element going to row 0, etc. This method will send a
    * <code>tableChanged</code> notification message to all the listeners.
    * @param columnName the identifier of the column being added
    * @param columnData optional data of the column being added
    public void addColumn(Object columnName, Vector columnData) {
    columnIdentifiers.addElement(columnName);
    if (columnData != null) {
    int columnSize = columnData.size();
    if (columnSize > getRowCount()) {
    dataVector.setSize(columnSize);
    justifyRows(0, getRowCount());
    int newColumn = getColumnCount() - 1;
    for(int i = 0; i < columnSize; i++) {
    Vector row = (Vector)dataVector.elementAt(i);
    row.setElementAt(columnData.elementAt(i), newColumn);
    else {
    justifyRows(0, getRowCount());
    fireTableStructureChanged();
    * Adds a column to the model. The new column will have the
    * identifier <code>columnName</code>. <code>columnData</code> is the
    * optional array of data for the column. If it is <code>null</code>
    * the column is filled with <code>null</code> values. Otherwise,
    * the new data will be added to model starting with the first
    * element going to row 0, etc. This method will send a
    * <code>tableChanged</code> notification message to all the listeners.
    public void addColumn(Object columnName, Object[] columnData) {
    addColumn(columnName, convertToVector(columnData));
    // Implementing the TableModel interface
    * Returns the number of rows in this data table.
    * @return the number of rows in the model
    public int getRowCount() {
    return dataVector.size();
    * Returns the number of columns in this data table.
    * @return the number of columns in the model
    public int getColumnCount() {
    return columnIdentifiers.size();
    * Returns the column name.
    * @return a name for this column using the string value of the
    * appropriate member in <code>columnIdentifiers</code>.
    * If <code>columnIdentifiers</code> does not have an entry
    * for this index, returns the default
    * name provided by the superclass
    public String getColumnName(int column) {
    Object id = null;
    // This test is to cover the case when
    // getColumnCount has been subclassed by mistake ...
    if (column < columnIdentifiers.size()) {
    id = columnIdentifiers.elementAt(column);
    return (id == null) ? getDefaultColumnName(column)
    : id.toString();
    * Returns true regardless of parameter values.
    * @param row the row whose value is to be queried
    * @param column the column whose value is to be queried
    * @return true
    public boolean isCellEditable(int row, int column) {
    return true;
    * Returns an attribute value for the cell at <code>row</code>
    * and <code>column</code>.
    * @param row the row whose value is to be queried
    * @param column the column whose value is to be queried
    * @return the value Object at the specified cell
    * @exception ArrayIndexOutOfBoundsException if an invalid row or
    * column was given
    public Object getValueAt(int row, int column) {
    Vector rowVector = (Vector)dataVector.elementAt(row);
    return rowVector.elementAt(column);
    * Sets the object value for the cell at <code>column</code> and
    * <code>row</code>. <code>aValue</code> is the new value. This method
    * will generate a <code>tableChanged</code> notification.
    * @param aValue the new value; this can be null
    * @param row the row whose value is to be changed
    * @param column the column whose value is to be changed
    * @exception ArrayIndexOutOfBoundsException if an invalid row or
    * column was given
    public void setValueAt(Object aValue, int row, int column) {
    Vector rowVector = (Vector)dataVector.elementAt(row);
    rowVector.setElementAt(aValue, column);
    fireTableCellUpdated(row, column);
    // Protected Methods
    * Returns a vector that contains the same objects as the array.
    * @param anArray the array to be converted
    * @return the new vector; if <code>anArray</code> is <code>null</code>,
    *                    returns <code>null</code>
    protected static Vector convertToVector(Object[] anArray) {
    if (anArray == null) {
    return null;
    Vector v = new Vector(anArray.length);
    for (int i=0; i < anArray.length; i++) {
    v.addElement(anArray[i]);
    return v;
    * Returns a vector of vectors that contains the same objects as the array.
    * @param anArray the double array to be converted
    * @return the new vector of vectors; if <code>anArray</code> is
    *                    <code>null</code>, returns <code>null</code>
    protected static Vector convertToVector(Object[][] anArray) {
    if (anArray == null) {
    return null;
    Vector v = new Vector(anArray.length);
    for (int i=0; i < anArray.length; i++) {
    v.addElement(convertToVector(anArray[i]));
    return v;

  • Drag from JTable to JTree

    Hello all,
    is there a way to drag row(s) of a JTable to a node in a JTree?
    I have a JTree that�s Drag and Drop enabled and wrks fine dragging one node to another (one by one...), but now I want to get data from a table to this tree. I have tried the method setDragEnabled(boolean) in the JTable object, but it didnt work...
    thanks
    D@zed

    This is related to bug 5011850:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5011850
    Crashes in the same place.

  • Preventing JTree updates from uncompleted JTable edits

    Hello there!!
    I have an applet that displays an xml file in a JTree. Each node of the table represents specific elements of the xml file (some are not displayed by design). Also on the applet is a JTable that updates the displayed information depending on what node of the tree is clicked. The information displayed in the table includes names and values of attributes and names and values of xml elements not displayed in the JTree.
    I can edit values in the table and update that tree effectively, so that is not a problem.
    The problem I have is that if the user enters a value in the table, does not press enter and then clicks on another tree node, the entered value is copied into the new tree node. I would like to ignore all values if the user does not specifically press enter.
    I have seen some code examples in previous posts that partially work, but can't get the entered values to be totally ignored.
    I'm currently using the following code to handle the 'didn't press enter' bug.
            table.getEditorComponent().addFocusListener(
                    new java.awt.event.FocusListener(){
                public void focusGained(java.awt.event.FocusEvent e) {}
                public void focusLost(java.awt.event.FocusEvent e){
                    if ( table.getEditingRow() > -1 &&
                            table.getEditingColumn() > -1 ){
                        ((javax.swing.DefaultCellEditor)table.getCellEditor()).stopCellEditing();
            });So my question is: How do I prevent the value entered in the table cell from being copied to the newly clicked on tree node? Any assistance would be great.
    Thanks (even just for reading!)
    Simon
    PS. When are we going to see the back of the stupid censorship in this forum?

    Not too sure if this will help but here goes...
    Normally in a JTable, editing is automatically stopped when the enter key is pressed so there is no need to do anything special there. If you don't want editing to stop when the mouse is clicked elsewhere in the table, what you should do is call cancelEditing() instead of stopEditing() in your focusLost method.
    ;o)
    V.V.

  • Creating a JTable as a leaf for JTree

    Is it possible to create a JTable as leaf node of a JTree..?
    I used treecellrenderer which returns JTable as component.. but i'm getting a single row of table in my tree..? How can i solve this..?

    bbritta,
    Thanks a lot.. for u'r support. But actually i don't want to have some kind of explorer type interface with a tree on the left side of a panel & a TABLE . I want to have a JTable as a leaf node in JTree. I mean i need JTable as node for Jtree.. But still teh code u suggested make some sense.. i will give a try.. Thanks..
    gussev,
    U got my problem..!
    "that is possible, at the beginning of the next month, even at the end of this I'm going to release several JavaBeans and "JTable as a node for a JTree" bean would be available. I'll send a message to forum. "
    I'm eagerly waiting for u'r message..
    Thanks
    Saran

Maybe you are looking for

  • While doing migo-goods receipt for production

    I am getting above message while doing migo please help Batch 0000000027 has the status <restricted-use> Message no. M7670 Diagnosis You are attempting to post a batch with status <restricted use> for a goods receipt. System Response Depending on the

  • MP3 files crash wirelessly shared connection

    I've been struggling with this for a while, and have just found a solution, but would appreciate an explanation if anyone can provide it. I have a couple of Windows PCs running iTunes 7.1. The library is stored on a networked disk, but is "owned" by

  • PlayStation 3 (320GB) Uncharted 3 Bundle

    I wanna order this product, but the specifications are quite vague. http://www.bestbuy.com/site/Sony+-+PlayStation+3+%28320GB%29+Uncharted+3+Bundle/3652529.p?id=1218424... I would like to know about the bluray and dvd player, which region area they c

  • PHOTOSHOP CS4 bit mode compatibility

    I have files in RGB and their bit modes are deactivated so I can't add another RGB photo (in 8-bit mode) into that file nor can I deactivate the bit mode in the photo to match the main files. How to I make these two images compatible??? Please help! 

  • XI, PI, ESA, ESR

    Hello Everyone, I have been working with XI and now started looking to upgrade XI to PI and calculating ROA, etc... As I am going to several docs, basically there is no change between XI and PI if we install latest service packs.  Am I right? Is ESR