1 Replies - 7726 Views - Last Post: 26 March 2013 - 10:48 AM

#1 qadeerhussain007  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 05-July 12

jtable custom model with table cell renderer

Posted 26 March 2013 - 09:50 AM

hello friends i have made a jtable and iam putting a jprogress bar in it now for jprogress bar aim using a table cell renderer and iam using the class which implement a table cell renderer

    public class TableRender implements TableCellRenderer
{
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      Object c=Interface.table.getModel().getColumnName(2);

        return (JProgressBar) c;
    }
    
    
}


and my code where iam getting this progress bar is

enter code here

    Interface.table.getModel().getColumnName(2).setCellRenderer(new TableRender());


now i changed my mind and iam using my own table model my question is how i acheive this kind of functionalities using my own table model my own table model class is


        public class MyModel extends AbstractTableModel
{
    String title []={"URL","Size","Progress","Remaining","Status"};
    LinkedList<TableData> RowData;
    public MyModel(LinkedList<TableData> RowData)
    {
        this.RowData= RowData;
    }

    @Override
    public int getRowCount() {
     //return RowData.size();
        return RowData.size();
    }

    @Override
    public int getColumnCount() {
        return 5;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
       switch (columnIndex){
            case 0: return RowData.get(rowIndex).getUrl();
            case 1: return RowData.get(rowIndex).getSize();
            case 2: return RowData.get(rowIndex).getProgress();
            case 3: return RowData.get(rowIndex).getRemaining();
            case 4: return RowData.get(rowIndex).getStatus();
            default: return "N/A";
            }
    }
    public  JProgressBar getColumn(TableData obj)
    {
        return obj.getProgress();
        
    }
    public void removeRow(int row)
    {
        RowData.remove(row);
    }
    public void addRow(TableData obj)
    {
        RowData.add(obj);
    }
    



now what kind of changees i can made in this line

enter code here
    Interface.table.getModel().getColumnName(2).setCellRenderer(new TableRender());


Is This A Good Question/Topic? 0
  • +

Replies To: jtable custom model with table cell renderer

#2 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10662
  • View blog
  • Posts: 39,590
  • Joined: 27-December 08

Re: jtable custom model with table cell renderer

Posted 26 March 2013 - 10:48 AM

Please stop duplicate posting. You have another thread already. Also, please stop posting in the wrong forums. The Java Advanced Discussion and Java Challenges subforums are not the places to post to get help on your coding problems.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1