Results 1 to 4 of 4
  1. #1
    dinu is offline Member
    Join Date
    Jan 2013
    Posts
    31
    Rep Power
    0

    Default Jtable dosent display anything ?

    I want to update the Jtable when a message is entered. The Jtable does not show any values . I also want to update the Jtable when new values are entered ?
    below is the code and snap shot of Image Jtable dosent display anything ?-1.jpg


    Java Code:
    
    import java.awt.image.BufferStrategy;
    import java.util.Scanner;
    
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.SwingWorker;
    import javax.swing.table.DefaultTableModel;
    
    
    public class flicker extends JFrame {
    	JTable table;            
    	DefaultTableModel model = new DefaultTableModel();  
        JButton Acknowledge;      
        JPanel Panel=new JPanel();           
        JScrollPane Pane;       
        JScrollPane Pane1;      
        JScrollPane Pane2;
        String[] Optlist = {"Show Alarm", "Show History", "Report Alarm (PDF)", "Report History (PDF)"};
        JComboBox Options=null;  
      
        BufferStrategy myStrategy;
        
        String p=null;
        String w=null;
    	String area=null;
    	
        int i,r;   
        String ip,selection,stso,group,message,p1,p2,Sensor;
        static String checkedval;
        static String Name;
        Double Value;
        
        Object data[][]=null;
        
        public flicker(String string) {
    		super(string);
    		 
    		  Panel.setLayout(null);
    	      getContentPane().add(Panel);    
      	                                                          
              start();
              
              Pane=new JScrollPane(table);
              Pane.setSize(500,500);
              
              Pane1=new JScrollPane(Acknowledge);
              Pane1.setSize(90,30);
              Pane1.setBounds(0,500,320,30);
              
              Pane2=new JScrollPane(Options);
              Pane2.setBounds(320,500,180,30);
              
              
              Panel.add(Pane);       
              Panel.add(Pane1);
              Panel.add(Pane2);       
              
         	  setSize(520,570);
       	      setDefaultCloseOperation(DISPOSE_ON_CLOSE);      
              setVisible(true);	
    	}
        
        private void start() 
        {
         try
            {  
                                 final Scanner sc = new Scanner(System.in);
                                 SwingWorker<Object, Object> worker = new SwingWorker<Object, Object>() 
                                	 {
                                         @Override
                                	    protected Object doInBackground()
                                	    {       
                                        	 System.out.println("Write message here: ");
                            	  				message=sc.nextLine();
                            	  				System.out.println("Message is: "+message);
                            	  				Object col[] = {"Sensor","Values","Arrival_Time","Status",""};
                            	  				if(!message.equals("ITS EMPTY"))
                            	  				{
                            	  					String[] parts = message.split("\t");
                    	  				            data = new Object[parts.length / 4][5];
                            	  				
                            	  					for (i = 0, r = 0; r < data.length; r++) 
                            	  					{                        	  						
                        	  						data[r][0] =  parts[i++];
                        	  					   //data[r][1] =  new Double(parts[i++]) ;
                        	  					    data[r][1] =  parts[i++] ;
                        	  					    data[r][2] = parts[i++];
                        	  					    data[r][3] = parts[i++];
                        	  					    p=(String) data[r][3];
                        	  					    w = (String) abc(p);
                        	  					    data[r][4]=Boolean.parseBoolean(w) ;
                        	  					  // System.out.println(data[r][4]);
                            	  					}               
                            	  					//System.out.println(java.util.Arrays.deepToString(data));
                            	  					
                                              //Display Table     
                            	  				model.setDataVector(data, col);
                            	  		      	  				
                            	  				 table = new JTable(model)
                                       	        {
                                       	            private static final long serialVersionUID = 1L;
                                       	            @Override
                                       	            public Class getColumnClass(int column) 
                                       	            {
                                       	                switch (column) {
                                       	                    case 0:
                                       	                        return String.class;
                                       	                    case 1:
                                       	                        return String.class;
                                       	                    case 2:
                                     	                        return String.class;
                                       	                    case 3:
                                   	                            return String.class;
                                       	                    default:
                                       	                        	return Boolean.class;
                                       	                    }
                                       	               }    
                                       	            };    
                                       	         publish(table);
                                	          }                       	  
                            	  				else
                            	  				{
                            	  					System.out.println("NO TABLE");    
                            	  				}                    	                                         
                            	  				return table;
                                	    }
                                                              
                                 protected void process(JTable table)
                                 {                                                       	        
                          table.setDefaultRenderer(Object.class, new CustomTableCellRenderer3());
    
                                table.setPreferredScrollableViewportSize(table.getPreferredSize()); 
                         table.getColumnModel().getColumn(4).setCellEditor(new CustomTableCellRenderer(new JCheckBox(),Name));
                        
                             model.fireTableDataChanged();
                             table.repaint();
                                  }                         
                                 };
                       worker.execute();
                       
    	  			
            }
         catch(Exception e)
         { 
           System.out.println("Exception Occured:" +e); 
              }   
        }
                                                                	                            
    	  private Object abc(String p)
    	     {		
    		   String val=null;
    				if(p.equals("ACK"))
    					 {
                       val="true";
    					  }
    				 else if(p.equals("nil"))
    					   {
    					     val="false";
    					    }
    		  return val;
    	       }
        
    }

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default Re: Jtable dosent display anything ?

    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,021
    Rep Power
    6

    Default Re: Jtable dosent display anything ?

    I can't see where you added your table to any JPanel. Also, it is usually discouraged from subclassing JFrame (or any other class unless additional functionality is being added). And class names (e.g. flicker) should be capitalized.

    Edit: Ok. Added to JScrollPane. Trying to determine problem.

    Regards,
    Jim
    Last edited by jim829; 04-26-2013 at 02:51 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,021
    Rep Power
    6

    Default Re: Jtable dosent display anything ?

    It appears you are adding a null table to your JScrollPane (System.out.println is your friend). Also, you might want to rework your nested anonymous classes. They can be pretty confusing to understand. And do a web search on Java naming conventions. Instance fields and packages should begin with lowercase letters, and class Names should start with upper case.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Using jTable to display query result
    By zenith666 in forum New To Java
    Replies: 2
    Last Post: 01-13-2012, 03:29 AM
  2. [SOLVED] Cant display data in jTable
    By tpyq in forum NetBeans
    Replies: 2
    Last Post: 12-09-2008, 03:42 PM
  3. JButton to display JTable
    By Nemesis777 in forum New To Java
    Replies: 0
    Last Post: 12-08-2008, 01:16 PM
  4. Display XML in JTable
    By boy22 in forum XML
    Replies: 2
    Last Post: 12-07-2008, 07:03 PM
  5. display rows in jtable
    By osval in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 09:54 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •