Inserting imageicon in jtable

Hi,
I want to insert imageicon in Jtable using AbstractTableModel.
Please help me out from this.

Ravi_Gupta wrote:
Use custon Cell RendererThere's no need to use a custom cell renderer.
Just override getColumnClass method of your model to return ImageIcon.class for the appropriate column, and add the imageicon to the model.

Similar Messages

  • Inserting row in JTable (runtime)

    i need to inserting row in JTable in runtime so tell me what it do

    dear farhanaj ,
    try this code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.table.*;
    /* <applet code=tableadd.class width=200 height=200>
    </applet>
    public class tableadd extends JApplet implements ActionListener
    Object[] data = new Object[5];
    DefaultTableModel defaulttablemodel = new DefaultTableModel();
    JTable jtable=new JTable(defaulttablemodel);
    JPanel jpanel= new JPanel();
    private     JPanel          topPanel,jpPanel;
    public     JTable          table;
    JButton jbutton1 = new JButton("create new row");
    JButton jbutton2 = new JButton("create new col");
    //JButton jbutton1=new Jbutton("r"),jbutton2=new Jbutton("c");
    public tableadd()
    for(int column=0 ; column<5 ; column++)
    defaulttablemodel.addColumn("column" + column);
    for(int row=0 ; row<5;row++)
    for(int column=0 ;column<5;column++)
    data[column]="cell" row "," + column;
    defaulttablemodel.addRow(data);
    //getContentPane().add(new JScrollPane(jtable) ,BorderLayout.CENTER);
    //getContentPane().add(new JPanel() ,BorderLayout.SOUTH);
    int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp = new JScrollPane(jtable , v, h);
    getContentPane().add(jsp, BorderLayout.CENTER);
    topPanel = new JPanel();
    jpPanel=new JPanel();
    topPanel.setLayout( new BorderLayout() );
    getContentPane().add(topPanel,BorderLayout.NORTH);
    getContentPane().add(jpPanel,BorderLayout.SOUTH);
    jpPanel.add(jbutton1);
    jpPanel.add(jbutton2);
    jbutton1.addActionListener(this);
    jbutton2.addActionListener(this);
    public void actionPerformed(ActionEvent e)
    if (e.getSource() == jbutton1)
    int numberrows = defaulttablemodel.getRowCount();
    int numbercolumns=defaulttablemodel.getColumnCount();
    Object[] data = new Object[numbercolumns];
    for(int column=0 ; column<numbercolumns;column++)
    data[column]="cell" numberrows "," +column;
    defaulttablemodel.addRow(data);
    else
    if (e.getSource() ==jbutton2)
    int numberrows=defaulttablemodel.getRowCount();
    int numbercolumns=defaulttablemodel.getColumnCount();
    defaulttablemodel.addColumn("column" + numbercolumns);
    for(int row=0; row<numberrows ; row++)
    defaulttablemodel.setValueAt("cell" row "," +numbercolumns ,row , numbercolumns);
                   System.out.println(row);
    //jtable.sizeColumnsToFit(0);

  • How to insert picture in JTable?

    I want to insert picture in JTable.
    But I don't know how to insert picture in JTable.
    My project must use it very much.
    Plaese help me.

    there is an example with sources
    C:\jdk140\demo\jfc\SwingSet2
    or
    YOUR_JDK\demo\jfc\SwingSet2

  • How to insert data from JTable to mysql Table....

    hello everybody
    i need help about how to insert data from JTable to mysql table... i know about how to create Table model...facing problem about how to insert data from JTable to mysql table....any helping link or code ... ill be thankfulll....for giving me solution...

    table1.getValueAt(table1.getSelectedRow(),0)you are getting the value of a selected row... or if you want you can just use a loop..
    for(.....){
    table1.getValueAt(x,y);
    }I think you know INSERT STATEMENT.. here on it just string concat
    sample e.g. (This not insert)
    "delete from accrule " +
                    "where ruleid= " + tblRA.getValueAt(tblRA.getSelectedRow(),0)+
                    " and accountname='"+tblRA.getValueAt(tblRA.getSelectedRow(),1)+"'"

  • How to insert jcheckbox in jtable

    hello
    i am user of oracle9i jdeveloper using jclient/swing .
    question:
    how to insert jcheckbox at a particular cell in jtable.
    please reply to me if anyone amongst you know the solution.
    thank you

    Please continue the discussion here: how to insert checkbox at a particular  cell  in jtable
    Correct me if this is not about the same subject.

  • Rendering ImageIcons in JTable cells

    Hi folks, anyone know how to:
    1. add a single ImageIcon to a JTable and then display the table, then add another imageicon and display again etc. etc...
    ... and...
    2. take a vector of imageicons and construct a JTable directly from this?
    These involve working with areas of Java I am, frankly, totally unfamiliar with and I'm actually really stuck with TableCellRenderers, JComponents, Repaint etc. so could use some assistance!
    Thank you all kindly,
    Jam

    JDK1.3 comes with a demo that shows the use of all Swing components. The table demo has a column displaying images. The code is included so you can see how it is done:
    code found in: jdk1.3\demo\jfc\SwingSet2
    execute demo: java -jar SwingSet2.jar

  • Need to use vector to insert data into JTable?

    hi
    i'm trying to insert data from mssql 2000 into JTable. The number of columns are fixed, but the number of rows are not, since it will depend on how many data retrieved from the database.
    The documentation says that vector class implements a growable array of objects, and I've seen some examples using vector such as from http://forum.java.sun.com/thread.jspa?forumID=57&threadID=238597 .
    I would like to know, in my case, do i need to set my column and row to use vector? or should i only set rows to use vector ? (since the row size will vary, while the column size will stick to 6).

    Because your JTable operation will be done on a table model, the selection of the initial data
    structure for the model is almost non-issue. In other words, whatever will do.
    See the javadoc for the DefaultTableModel class, which you will eventually use, especially the
    construcotr part.

  • Inserting cell inside JTable cell

    Hi!
    i want to insert another cell inside a JTable cell, so that they are both displayed.
    Is it possible to do that.

    I was thinking about something like the below. I have not tested it, so let me know if it works.
    public class TwoCellTableCellRenderer extends DefaultTableCellRenderer {
         public Component getTableCellRendererComponent(JTable table,
                Object value,
                boolean isSelected,
                boolean hasFocus,
                int row,
                int column) {
              JPanel panel = new JPanel();
              panel.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
              panel.add(new JTextField(), null);
              panel.add(new JTextField(), null);
              return panel;
         protected void setValue(Object value) {
              // DO SOMETHING HERE TO PARSE YOUR TWO VALUES
    public class YourTwoCellDataClass {
    yourTable.setDefaultRenderer (YourTwoCellDataClass.class,
         new TwoCellTableCellRenderer());

  • Unable to insert JRadio in JTable.

    Hi All,
    I'am very new to swing development and working on JTable which should contain 4 columns (Index,RadioButton,Device Name and Device Number).The rows are added dynamically.I have written classes MyTableModel, MyTableRadioButtonRenderer and MyTableRadioButtonEditor which I'am using in my main class.
    The problem is that when I execute the main class I get a Table view with all other values as desired but the values returned by the radiobutton in the second column is null (i.e my second column is filled with empty spaces).I have tried several ways but failed in displaying the table with radiobuttons.
    Can anyone please guide me through this.
    I have pasted my code below.
    //This is My main class
    JPanel panelList = new JPanel(new BorderLayout());
    //Get the list of all Devices where each device has properties like device_name,device_number etc.
    ArrayList allDevices = getMyDevices();
    JRadioButton jRadio[] = new JRadioButton[allDevices.size()];
    ButtonGroup radioButtonGroup = new ButtonGroup();
    Vector row = new Vector(alDevices.size());
    Vector addRow;
    for (int i = 0; i < allDevices.size(); i++) {
    Integer index = new Integer(i+1);
    myDevice = (Device)allDevices.get(i);
    addRow = new Vector();
    addRow.add((Integer)index);
    addRow.add((JRadioButton)jRadio);
    addRow.add(myDevice.getName());
    addRow.add(myDevice.getNumber());
    row.add(i,addRow);
    MyTableModel deviceTableModel = new MyTableModel(row);
    JTable deviceTable = new JTable(deviceTableModel);
    //Adding all the radio buttons to the button group.
    for(int x = 0;x<row.size();x++)
    radioButtonGroup.add((JRadioButton)deviceTable.getValueAt(x,1));
    deviceTable.getColumn("Select").setCellRenderer(new MyTableRadioButtonRenderer());
    deviceTable.getColumn("Select").setCellEditor(new MyTableRadioButtonEditor(new JCheckBox()));
    deviceTable.setVisible(true);
    deviceTable.setIntercellSpacing(new Dimension(2,2));
    panelList.add(deviceTable,BorderLayout.CENTER);
    public class MyTableModel extends AbstractTableModel {
    private Vector datalist;
    private String[] columns = {" ", "Select", "Device Name", "Device Number"};
    public MyTableModel() {
    public MyTableModel(Vector l) {
    datalist = l;
    public String getColumnName(int col) {
    return columns[col];
    public int getColumnCount() {
    return columns.length;
    public int getRowCount() {
    return datalist.size();
    public Object getValueAt(int row, int col) {
    Vector rowList = (Vector)datalist.get(row);
    if(rowList.firstElement()!=null) {
    switch (col) {
    case 0:
    return (Integer) rowList.elementAt(0);
    case 1:
    return (JRadioButton) rowList.elementAt(1);
    case 2:
    return (String) rowList.elementAt(2);
    case 3:
    return (String) rowList.elementAt(3);
    default:
    return null;
    }else return null;
    //This one method decides exactly which cells are editable.
    public boolean isCellEditable(int row, int col) {
    switch (col) {
    case 0: //Index
    return false;
    case 1: //RadioButton
    return true;
    case 2: //Device Name
    return false;
    case 3: //Device Number
    return false;
    default:
    return false;
    /** This one method tells the view which type of object will be displayed.
    * This allows the JTable to display the data in a way that is most appropriate
    * for the type of object that exists in that row.
    public Class getColumnClass(int col) {
    switch (col) {
    case 0: //Index
    return Integer.class;
    case 1: //RadioButton
    return JRadioButton.class;
    case 2: //Device Name
    return String.class;
    case 3: //Device Number
    return String.class;
    default:
    return null;
    public class MyTableRadioButtonRenderer implements TableCellRenderer {
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column) {
    if (value==null) return null;
    return (Component)value;
    public class MyTableRadioButtonEditor extends DefaultCellEditor implements ItemListener {
    private JRadioButton button;
    public MyTableRadioButtonEditor(JCheckBox checkBox) {
    super(checkBox);
    public Component getTableCellEditorComponent(JTable table, Object value,
    boolean isSelected, int row, int column) {
    if (value==null) return null;
    button = (JRadioButton)value;
    button.addItemListener(this);
    return (Component)value;
    public Object getCellEditorValue() {
    button.removeItemListener(this);
    return button;
    public void itemStateChanged(ItemEvent e) {
    super.fireEditingStopped();

    <sigh>
    Apparently the profusion of topics returned in the forum search has left us baffled...
    Now... again I say - RTFA..
    1) A JTable uses single instance components to render its data - this only makes sense as a table containg thousands of records could become a little heavy if each cell was a label.... so in order to keep things manageable it specifies a RENDERER for each data type, determined by class, which is iterated through each value to produce an on-screen image which is NOT a component. That's all the cell is, an image. NB! This is CLEARLY stated in the API. So, as previously stated, providing a JRadioButton to display a BOOLEAN value is absolute pants... it goes against the whole purpose behind this functionality and does nothing for performance. If you would like the BOOLEAN value displayed as a JRadioButton, you would need to sub JRadioButton and implement TabelCellRenderer... then simply call:
    myTable.setDefaultRenderer(Boolean.class, myCustomRadio);Now, each time the table encounters a BOOLEAN value, it will use your specified renderer to draw an IMAGE of a JRadioButton with its state determined by the BOOLEAN value.. , (NB! this is an IMAGE not a JRadioButton).
    2) The same goes for your EDITOR. Again, creating a billion unique components to edit each cell is quite obviously senseless... so each type has its own EDITOR specified..., the editor returned when you click on an editable cell is specific to that type. So... your choices are to create another subbed JRadioButton to handle this, or have the RENDERER perform this function for you, (which it can do as it isn't tied to any particular cell). Thus:
    myTable.setDefaultEditor(Boolean.class, myCustomRadio);Will provide you with the required functionality...
    Take to heart the comment about the API - all of the above is there and more....
    With that said, can you see why using a ButtonGroup did not work..?

  • Help with updating imageIcon in JTable

    Hi All
    Please I am hoping that some out there will know what is going on with this
    I am setting a Cell with a ImageIcon with this code
            Object[] data = {
                rSet.getString(1),
                new ImageIcon("imagesTest/" + "check" + rSet.getString(2) + ".png"),
                rSet.getString(2),
                "yes",
                rSet.getString(3)};
            model.addRow(data);and this work fine as I have this set to the table
          public Class getColumnClass(int c) {
            return getValueAt(1, c).getClass();
          }Now I want to update the ImageIcon with a new image that I create
    and I am trying to set the new ImageIcon to the cell with this code
          model.setValueAt(new ImageIcon("imagesTest/" + "check" +table.getValueAt
    (table.getSelectedRow(), 2) +".png"), table.getSelectedRow(), 1);but it does not want to paint it
    I have tried
    repaint();
    super.repaint();
    revalidate();I have also tried reloading the data by removing all the rows in the model with this
        model.setRowCount(0);
       then reloading the data.
    It seams like it holds ImageIcom in memory or something .
    Has anyone got an idea on how I can get this to work
    p.s I don't have the full code to show as it is hard to pull it apart.
    I hope I have given enough code to so you what is going on.
    Thanks for any insight into this
    Craig

    You should write an appropriate cell renderer.
    If the cell is defined editable, you'd also need cell editor.

  • Need help with inserting rows in ResultSet and JTable

    hello Guru!
    i have inserted a row in my result set and i want that my table shows this row promptly after i have inserted it in my result set...
    but when i use following code for my resultset:
    rs.moveToInsertRow();
    rs.updateInt(1,nr);
    rs.updateString(2, name);
    rs.insertRow();
    Record are inserted in resultset and database but not shown in my JTable??
    Anyone a Clue to without reexecuting the query how can i display inserted row in JTable
    http://download-west.oracle.com/docs/cd/A87860_01/doc/java.817/a83724/resltse7.h
    I have refrered the following links but still clue less help Guruuuuuuu
    i m really in trobble??????

    i am just near by the Solution using the Database Metadata
    by couldn't get the ideaaaa
    ==================================================
    http://download-west.oracle.com/docs/cd/A87860_01/doc/java.817/a83724/resltse7.htm
    Seeing Database Changes Made Internally and Externally
    This section discusses the ability of a result set to see the following:
    its own changes (DELETE, UPDATE, or INSERT operations within the result set), referred to as internal changes
    changes made from elsewhere (either from your own transaction outside the result set, or from other committed transactions), referred to as external changes
    Near the end of the section is a summary table.
    Note:
    External changes are referred to as "other's changes" in the Sun Microsystems JDBC 2.0 specification.
    Seeing Internal Changes
    The ability of an updatable result set to see its own changes depends on both the result set type and the kind of change (UPDATE, DELETE, or INSERT). This is discussed at various points throughout the "Updating Result Sets" section beginning on , and is summarized as follows:
    Internal DELETE operations are visible for scrollable result sets (scroll-sensitive or scroll-insensitive), but are not visible for forward-only result sets.
    After you delete a row in a scrollable result set, the preceding row becomes the new current row, and subsequent row numbers are updated accordingly.
    Internal UPDATE operations are always visible, regardless of the result set type (forward-only, scroll-sensitive, or scroll-insensitive).
    Internal INSERT operations are never visible, regardless of the result set type (neither forward-only, scroll-sensitive, nor scroll-insensitive).
    An internal change being "visible" essentially means that a subsequent getXXX() call will see the data changed by a preceding updateXXX() call on the same data item.
    JDBC 2.0 DatabaseMetaData objects include the following methods to verify this. Each takes a result set type as input (ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_SENSITIVE, or ResultSet.TYPE_SCROLL_INSENSITIVE).
    boolean ownDeletesAreVisible(int) throws SQLException
    boolean ownUpdatesAreVisible(int) throws SQLException
    boolean ownInsertsAreVisible(int) throws SQLException
    Note:
    When you make an internal change that causes a trigger to execute, the trigger changes are effectively external changes. However, if the trigger affects data in the row you are updating, you will see those changes for any scrollable/updatable result set, because an implicit row refetch occurs after the update.
    Seeing External Changes
    Only a scroll-sensitive result set can see external changes to the underlying database, and it can only see the changes from external UPDATE operations. Changes from external DELETE or INSERT operations are never visible.
    Note:
    Any discussion of seeing changes from outside the enclosing transaction presumes the transaction itself has an isolation level setting that allows the changes to be visible.
    For implementation details of scroll-sensitive result sets, including exactly how and how soon external updates become visible, see "Oracle Implementation of Scroll-Sensitive Result Sets".
    JDBC 2.0 DatabaseMetaData objects include the following methods to verify this. Each takes a result set type as input (ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_SENSITIVE, or ResultSet.TYPE_SCROLL_INSENSITIVE).
    boolean othersDeletesAreVisible(int) throws SQLException
    boolean othersUpdatesAreVisible(int) throws SQLException
    boolean othersInsertsAreVisible(int) throws SQLException
    Note:
    Explicit use of the refreshRow() method, described in "Refetching Rows", is distinct from this discussion of visibility. For example, even though external updates are "invisible" to a scroll-insensitive result set, you can explicitly refetch rows in a scroll-insensitive/updatable result set and retrieve external changes that have been made. "Visibility" refers only to the fact that the scroll-insensitive/updatable result set would not see such changes automatically and implicitly.
    Visibility versus Detection of External Changes
    Regarding changes made to the underlying database by external sources, there are two similar but distinct concepts with respect to visibility of the changes from your local result set:
    visibility of changes
    detection of changes
    A change being "visible" means that when you look at a row in the result set, you can see new data values from changes made by external sources to the corresponding row in the database.
    A change being "detected", however, means that the result set is aware that this is a new value since the result set was first populated.
    With Oracle8i release 8.1.6 and higher, even when an Oracle result set sees new data (as with an external UPDATE in a scroll-sensitive result set), it has no awareness that this data has changed since the result set was populated. Such changes are not "detected".
    JDBC 2.0 DatabaseMetaData objects include the following methods to verify this. Each takes a result set type as input (ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_SENSITIVE, or ResultSet.TYPE_SCROLL_INSENSITIVE).
    boolean deletesAreDetected(int) throws SQLException
    boolean updatesAreDetected(int) throws SQLException
    boolean insertsAreDetected(int) throws SQLException
    It follows, then, that result set methods specified by JDBC 2.0 to detect changes--rowDeleted(), rowUpdated(), and rowInserted()--will always return false with the 8.1.6 Oracle JDBC drivers. There is no use in calling them.
    Summary of Visibility of Internal and External Changes
    Table 12-1 summarizes the discussion in the preceding sections regarding whether a result set object in the Oracle JDBC implementation can see changes made internally through the result set itself, and changes made externally to the underlying database from elsewhere in your transaction or from other committed transactions.
    Table 12-1 Visibility of Internal and External Changes for Oracle JDBC
    Result Set Type Can See Internal DELETE? Can See Internal UPDATE? Can See Internal INSERT? Can See External DELETE? Can See External UPDATE? Can See External INSERT?
    forward-only
    no
    yes
    no
    no
    no
    no
    scroll-sensitive
    yes
    yes
    no
    no
    yes
    no
    scroll-insensitive
    yes
    yes
    no
    no
    no
    no
    For implementation details of scroll-sensitive result sets, including exactly how and how soon external updates become visible, see "Oracle Implementation of Scroll-Sensitive Result Sets".
    Notes:
    Remember that explicit use of the refreshRow() method, described in "Refetching Rows", is distinct from the concept of "visibility" of external changes. This is discussed in "Seeing External Changes".
    Remember that even when external changes are "visible", as with UPDATE operations underlying a scroll-sensitive result set, they are not "detected". The result set rowDeleted(), rowUpdated(), and rowInserted() methods always return false. This is further discussed in "Visibility versus Detection of External Changes".
    Oracle Implementation of Scroll-Sensitive Result Sets
    The Oracle implementation of scroll-sensitive result sets involves the concept of a window, with a window size that is based on the fetch size. The window size affects how often rows are updated in the result set.
    Once you establish a current row by moving to a specified row (as described in "Positioning in a Scrollable Result Set"), the window consists of the N rows in the result set starting with that row, where N is the fetch size being used by the result set (see "Fetch Size"). Note that there is no current row, and therefore no window, when a result set is first created. The default position is before the first row, which is not a valid current row.
    As you move from row to row, the window remains unchanged as long as the current row stays within that window. However, once you move to a new current row outside the window, you redefine the window to be the N rows starting with the new current row.
    Whenever the window is redefined, the N rows in the database corresponding to the rows in the new window are automatically refetched through an implicit call to the refreshRow() method (described in "Refetching Rows"), thereby updating the data throughout the new window.
    So external updates are not instantaneously visible in a scroll-sensitive result set; they are only visible after the automatic refetches just described.
    For a sample application that demonstrates the functionality of a scroll-sensitive result set, see "Scroll-Sensitive Result Set--ResultSet5.java".
    Note:
    Because this kind of refetching is not a highly efficient or optimized methodology, there are significant performance concerns. Consider carefully before using scroll-sensitive result sets as currently implemented. There is also a significant tradeoff between sensitivity and performance. The most sensitive result set is one with a fetch size of 1, which would result in the new current row being refetched every time you move between rows. However, this would have a significant impact on the performance of your application.
    how can i implement this using
    JDBC 2.0 DatabaseMetaData objects include the following methods to verify this. Each takes a result set type as input (ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_SENSITIVE, or ResultSet.TYPE_SCROLL_INSENSITIVE).
    boolean deletesAreDetected(int) throws SQLException
    boolean updatesAreDetected(int) throws SQLException
    boolean insertsAreDetected(int) throws SQLException

  • Animated .gif in JTable cell

    Hi -
    I have an actual animated .gif that I would like to display in a JTable's cell. By 'actual animated .gif', I mean that it is one file that is animated, and not a succession of files that I would loop through to look like animation.
    I have edited the following code that I found in a previous post. My .gif does display in the JTable and animates only ONCE. Once it animates once, it stops. How can I cause it to keep looping through and repeating the animation?
    Thanks!
    Kelly
    Code below:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class AnimatedIconTableExample extends JFrame
    public AnimatedIconTableExample()
    super("AnimatedIconTable Example");
    final Object[][] data = new Object[][]
    { new ImageIcon("images/Upload.gif") }
    final Object[] column = new Object[]
    { "Image Uploading" };
    AbstractTableModel model = new AbstractTableModel()
    public int getColumnCount()
    return column.length;
    public int getRowCount()
    return data.length;
    public String getColumnName(int col)
    return (String) column[col];
    public Object getValueAt(int row, int col)
    return data[row][col];
    public Class getColumnClass(int col)
    return ImageIcon.class;
    JTable table = new JTable(model);
    table.setRowHeight(50);
    setImageObserver(table);
    JScrollPane pane = new JScrollPane(table);
    getContentPane().add(pane);
    private void setImageObserver(JTable table)
    TableModel model = table.getModel();
    int colCount = model.getColumnCount();
    int rowCount = model.getRowCount();
    for (int col = 0; col < colCount; col++)
    if (ImageIcon.class == model.getColumnClass(col))
    for (int row = 0; row < rowCount; row++)
    ImageIcon icon = (ImageIcon) model.getValueAt(row, col);
    if (icon != null)
    icon.setImageObserver(new CellImageObserver(table, row,
    col));
    class CellImageObserver implements ImageObserver
    JTable table;
    int row;
    int col;
    CellImageObserver(JTable table, int row, int col)
    this.table = table;
    this.row = row;
    this.col = col;
    public boolean imageUpdate(Image img, int flags, int x, int y, int w,
    int h)
    if ((flags & (FRAMEBITS | ALLBITS)) != 0)
    Rectangle rect = table.getCellRect(row, col, false);
    table.repaint(rect);
    return (flags & (ALLBITS | ABORT)) == 0;
    public static void main(String[] args)
    AnimatedIconTableExample frame = new AnimatedIconTableExample();
    frame.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    frame.setSize(300, 150);
    frame.setVisible(true);

    I've heard of that problem before... I think it has something to do with how the image is loaded. I found an example of how Sun does animated gifs here: http://java.sun.com/products/java-media/2D/samples/suite/Image/DukeAnim.java
    I hope it helps.

  • Transfer Data from a JTable to the table model

    Hi
    I' looking for a simple method to transfer the last user input in a table to the table model.
    For example:
    In a Dialog the user insert in a JTable a few values and leaves with OK. But the last input is not saved in the model. It is just saved after selecting a new field in the JTable before leaving the Dialog.
    Is there a call to transfer all input to the model?
    Thanks
    Guido

    class MyJTable extends JTable (
    public boolean validateInput() {
    if(isEditing()) {
    return cellEditor.stopCellEditing();
    return true;
    Call this method whenever you want the input value to be stored in the table model. The return value can be false if the input isn't valid, this will depend on the cell editor.
    The idea is:
    Ask if the table has an editor activated. (isEditing())
    If so, request the editor to store the value in the model.
    I haven't prouved the code, sorry, but I hope you get the idea and helps.

  • Insert Table into jScrollPanel?

    I want to insert a new JTable into the jScrollPane.
    It works, but the Table wont appear in the middle.
    Here is a Picture of the Layout:
    http://img254.imageshack.us/my.php?image=hujodstworx9.jpg
    Can someone plz tell me howto insert into jScrollPane and make the right Layout for the Table????
    private void RenewMainTable(){
              remove(jTable1);
              jTable=getJTable1();
              jScrollPane4.setBounds(jTable.getBounds());
              jScrollPane4.setViewportView(jTable);
                    //Renew every every Component
                    SwingUtilities.updateComponentTreeUI(this);

    Der funktionierende Code sieht so aus.
              //delete The Table from Frame and Create a new jTable     
              remove(jTable1);
              jTable=getJTable1();
              //inser new Table into jScrollPane4
              jScrollPane4.setViewportView(jTable);
              //Set the Table to the Position of Table??!!!
              JViewport viewport= jScrollPane4.getViewport();
              viewport.setViewPosition(viewport.getLocation());
              SwingUtilities.updateComponentTreeUI(this);This crazy Code works, the "viewport" Object has Methods to Move the Content inside tthe jScrollPane.
    I Said Java to Place jScrollPane4 to the place of jScrollPane4??????? Dont know why it works, but it does.

  • TableCellRenderer for a JTableCell contains imageIcon

    Hi, all.
    I am writing a TableCellRenderer for a column in JTable which contains imageIcon. It sets the background of the cell to a specific color. It worked fine when the column's datatype is string. But when the datatype of the cell is an imageIcon, the setBackground method somehow overlaps the imageIcon, basically, I can't see the image Icon anymore. As I understand, while the datatype is imageIcon, the JTable basically Centers the imageIcon on a JLabel, then when I set the background of JLabel to a color, it should work, right? Here is the code, any help would be greately appreciated.
    <pre>
    package org.anser.newshound.gui;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.util.*;
    import java.io.*;
    public class TableCellRendererForThumbnailTable extends DefaultTableCellRenderer
    public static final Color DELETE_COLOR = Color.red;
    public static final Color NULL_COLOR = Color.white;
    private int[] rowStatus;
    public TableCellRendererForThumbnailTable(int[] rowStatus){
    super();
    this.rowStatus = rowStatus;
    public Component getTableCellRendererComponent(JTable table,
    Object value,
    boolean isSelected,
    boolean hasFocus,
    int row,
    int column){
    JLabel c = (JLabel) super.getTableCellRendererComponent(table,
    value,
    isSelected,
    hasFocus,
    row,
    column);
    c.setOpaque(true);
    if ( rowStatus[row] != -1 ) {
    if ( rowStatus[row] == ThumbAndMetaResultViewer.ACTION_DELETE ){
    c.setBackground( DELETE_COLOR );
    c.setForeground( Color.black );
    else {
    c.setBackground( NULL_COLOR );
    c.setForeground( Color.black);
    return c;
    </pre>

    I don't see that you are calling setIcon anywhere in the code - you need to make a change:
    c.setOpaque(true);
    // Add this  ------------8<-----------
    if (value instanceof Icon)
        c.setIcon((Icon) value);
    // ---------------------8=-----------
    if ( rowStatus[row] != -1 ) {
    ...Mitch Goldstein
    Author, Hardcore JFC (Cambridge Univ Press)
    [email protected]

Maybe you are looking for

  • Why did you get rid of the track option in ALL Revel apps?

    I am a subscribed Revel user that was once happy with what Revel offered but NOT anymore.  I organize my photos inside albums by events.  Why?  Because that is the ONLY organization available from Revel without creating thousands of albums.  So why d

  • How to implement Message Sequencing  other than mediator

    Hi All, I am looking for a solution to implement the message sequencing option for the below integration scenario between Order management module and projects module using SOA and AIA 11g. 1. The source system triggering requests is the Order managem

  • Install deskjet 1515 on mac os x 10.5

    Hello, I bought a new printer - Officejet 1515 ink advantage which am expected to use on my mac running Mac os X 10.5. Can someone help to get a driver for this printer so that I can use and enjoy my new printer on my mac.

  • I Have a Problem---LCR_GET_OWN_BUSINESS_SYSTEM - NO_BUSINESS_SYSTEM

    Hi!   When I used the Transaction SXI_CACHE for refreshing my Cache the following error is getting displayed.... LCR_GET_OWN_BUSINESS_SYSTEM - NO_BUSINESS_SYSTEM But i have made all the neccessary configurations in my SLD for the Business systems....

  • OCS Single-box installation for windows??

    hi. do i have to install Oracle9i Database, before i install OCS single-box for windows? any one have any idea?