473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Why I cannot see the updated values of JTable in Java UI?

I have a Download Manager project and when the download starts I must see the progress,speed and other related data about downloads.When the user add a URL , I can see the new download in the JTable but not in progress, I just saw that its progress in 0% and when I click some cell in the list and then again click another cell, I saw that it changed but why I must click it.If I don't click those downoads list' cells, i cannot see the progress.I also used Obsservable class and in the Download class I wrote
Expand|Select|Wrap|Line Numbers
  1.  // Notify observers that this download's status has changed.
  2.         public void stateChanged() {
  3.             setChanged();
  4.             notifyObservers();
  5.         }
  6.  
Here is the TableModel.Its object is created in DownloadManagerView(my view class).
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. import javax.swing.*;
  3. import javax.swing.table.*;
  4. import downloadmanager.controller.DownloadManagerSystem;
  5. import downloadmanager.model.Download;
  6.  
  7. // This class manages the download table's data.
  8. class DownloadsTableModel extends AbstractTableModel
  9.         implements Observer {
  10.  
  11.     // These are the names for the table's columns.
  12.     private static final String[] columnNames = {"URL", "Name",
  13.     "Size", "Progress %","Status","Time Left","Transfer Rate","Date"};
  14.  
  15.     // These are the classes for each column's values.
  16.     private static final Class[] columnClasses = {String.class,
  17.     String.class, String.class,JProgressBar.class, String.class, String.class,String.class,Date.class};
  18.  
  19.  
  20.   // Add a new download to the table.
  21.  
  22.     public void addDownloadToTable(Download download) {
  23.  
  24.         download.addObserver(this);
  25.  
  26.         // Fire table row insertion notification to table.
  27.         fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1);
  28.     }
  29.  
  30.     // Get a download for the specified row.
  31.     public Download getDownload(int row) {
  32.         return (Download) DownloadManagerSystem.getArrayList().get(row);
  33.     }
  34.  
  35.     // Remove a download from the list.
  36.     public void clearDownload(int row) {
  37.         DownloadManagerSystem.getArrayList().remove(row);
  38.  
  39.         // Fire table row deletion notification to table.
  40.         fireTableRowsDeleted(row, row);
  41.     }
  42.  
  43.     // Get table's column count.
  44.     public int getColumnCount() {
  45.         return columnNames.length;
  46.     }
  47.  
  48.     // Get a column's name.
  49.     public String getColumnName(int col) {
  50.         return columnNames[col];
  51.     }
  52.  
  53.     // Get a column's class.
  54.     public Class getColumnClass(int col) {
  55.         return columnClasses[col];
  56.     }
  57.  
  58.     // Get table's row count.
  59.     public int getRowCount() {
  60.  
  61.         return DownloadManagerSystem.getArrayList().size();
  62.  
  63.     }
  64.  
  65.     // Get value for a specific row and column combination.
  66.     public Object getValueAt(int row, int col) {
  67.  
  68.         Download download = (Download)DownloadManagerSystem.getArrayList().get(row);
  69.         switch (col) {
  70.             case 0: // URL
  71.                 return download.getUrl();
  72.             case 1: // Name
  73.                 return download.getName();
  74.             case 2: // Size
  75.                 int size = download.getSize();
  76.                 return (size == -1) ? "" : Integer.toString(size);
  77.  
  78.             case 3: // Progress
  79.                  return new Float(download.getProgress());
  80.  
  81.             case 4://Status
  82.                 return Download.STATUSES[download.getStatus()];
  83.             case 5: //TimeLeft
  84.                 return download.getTimeLeft();
  85.             case 6://TransferRate
  86.                 return download.getSpeed();
  87.             case 7:// Date
  88.                 return download.getDate();
  89.  
  90.  
  91.         }
  92.         return "";
  93.     }
  94.  
  95.   /* Update is called when a Download notifies its
  96.      observers of any changes */
  97.     public void update(Observable o, Object arg) {
  98.         int index = DownloadManagerSystem.getArrayList().indexOf(o);
  99.  
  100.         // Fire table row update notification to table.
  101.         fireTableRowsUpdated(index, index);
  102.     }
  103. }
The arraylist is created in model class DownloadManager.java and I call the ArrayList in the TableModel.Instead of creating two lists I used the Arraylist in the model.Is my problem related with this?
Before model I created the list and I made the adding to list process in view and It was working.But now I must do the project in the MVC structure, so I only created the list in the Model.Now, I cannot see any updated data about the downloads why is it so?I also uploaded my project zip.Please help.
Attached Files
File Type: zip DownloadManagerMVC1.zip (337.7 KB, 59 views)
Apr 27 '13 #1
0 1178

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Newasps | last post by:
Hi guys, I have a problem with UpdateCommand Event. In tihs event Ä°'m creating required controls to get that controls' values and also get them. But when I try to get updated values I'm getting the...
0
by: Ozer | last post by:
Hi guys, I need some help. In my datagrid's updatecommand event i'm trying to get textboxes values and also do it. But when i update the values in textboxes and fire the event, I can't get the...
0
by: Anil Kumar Lakky Reddy | last post by:
I have seen lots of people complaining about not getting updated values from edit columns of datagrid. I had similar problem, I figured I was refreshing the data on each page load. I fixed it by...
1
by: Jawad Aman via DotNetMonster.com | last post by:
hi I have a problem in working with ASP.NET controls. I have a Sign_UP form. After filling out all the values i click save button, the data is saved in the database. When i click edit and edit...
0
by: LamSoft | last post by:
I cannot get values from detailview, here is the demo code... <Fields> <asp:BoundField DataField="serverip" HeaderText="Server IP" ReadOnly="true" SortExpression="serverip" /> <asp:BoundField...
6
by: Peted | last post by:
Hi, im wanting to store some custom text strings in the app.config file of a c# app, to be retreived and updated when the app runs. using c# 2005 express in my testing i am using the code...
5
kaleeswaran
by: kaleeswaran | last post by:
hi! how to get a cursor values inside the java.i written procedure for getting 3 columns values like menuName,menuId,targetUrl it depends upon menuId so i am getting bulk values so i am using...
1
by: srinivasyadavkota | last post by:
Hi Experts here, Pls help. In my WebApplication from Home page(i.e parent window) i am sending the values to child window(i.e popup page) In the popup page(i.e child window) I am storing the...
1
by: ahmee | last post by:
this my program code these are my errors below please help me out....guys operater % cannot be applied to java.lang.String.int operater / cannot be applied to java.lang.String.int operater +...
1
by: JanineXD | last post by:
Hey, I seem to have a problem on a Java Swing Program with ActionListener. I've tried to use getSource in our class but seem don't have an idea why it won't work when I tried to program at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.