Cant update JTable?

When I in my ActionListener try to update mu JTable by fireTableDataChanged() nothing happens? Can anyone help me with this?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.swing.table.*;
import java.text.*;
class Kalender extends JFrame implements ActionListener
Container contentPane = getContentPane();
JScrollPane scrollPane;
JTable table;
MyTableModel myModel;
JButton back = new JButton("<<");
JButton forward = new JButton(">>");
JLabel frem = new JLabel();
Icon fremIcon= new ImageIcon(this.getClass().getResource("frem.gif"));
JLabel tilbage = new JLabel();
Icon tilbageIcon = new ImageIcon(this.getClass().getResource("tilbage.gif"));
Kalender()
contentPane.setLayout(null);
myModel = new MyTableModel();
table = new JTable(myModel);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
DefaultTableCellRenderer tcrColumn = new DefaultTableCellRenderer();
tcrColumn.setHorizontalAlignment(JTextField.CENTER);
table.getColumnModel().getColumn(0).setCellRenderer(tcrColumn);
table.getColumnModel().getColumn(1).setCellRenderer(tcrColumn);
table.getColumnModel().getColumn(2).setCellRenderer(tcrColumn);
table.getColumnModel().getColumn(3).setCellRenderer(tcrColumn);
table.getColumnModel().getColumn(4).setCellRenderer(tcrColumn);
table.getColumnModel().getColumn(5).setCellRenderer(tcrColumn);
table.getColumnModel().getColumn(6).setCellRenderer(tcrColumn);
//table.getColumnModel().getColumn(7).setCellRenderer(tcrColumn);
table.getColumnModel().getColumn(0).setPreferredWidth(80);
table.getColumnModel().getColumn(1).setPreferredWidth(80);
table.getColumnModel().getColumn(2).setPreferredWidth(80);
table.getColumnModel().getColumn(3).setPreferredWidth(80);
table.getColumnModel().getColumn(4).setPreferredWidth(80);
table.getColumnModel().getColumn(5).setPreferredWidth(80);
table.getColumnModel().getColumn(6).setPreferredWidth(80);
//table.getColumnModel().getColumn(7).setPreferredWidth(80);
table.setRowHeight(50);
scrollPane = new JScrollPane(table);
scrollPane.setBounds(20,20,604,330);
getContentPane().add(scrollPane);
back.setBounds(280,400,50,20);
back.addActionListener(this);
contentPane.add(back);
forward.setBounds(340,400,50,20);
forward.addActionListener(this);
contentPane.add(forward);
public void actionPerformed( ActionEvent e )
if(e.getSource()==back)
myModel.maaned--;
myModel.fireTableDataChanged();
System.out.println(myModel.maaned);
if(e.getSource()==forward)
myModel.maaned++;
myModel.fireTableDataChanged();
System.out.println(myModel.maaned);
class MyTableModel extends AbstractTableModel
final String[] columnNames = {//"Uge",
"Mandag",
"Tirsdag",
"Onsdag",
"Torsdag",
"Fredag",
"L�rdag",
"S�ndag"};
final Object[][] data=new Object[6][7];
int aarTaeller=0;
int maanedTaeller=0;
int maaned=0;
MyTableModel()
Calendar calendar = new GregorianCalendar();
int aar = calendar.get(calendar.YEAR+aarTaeller);
maaned = (calendar.get(calendar.MONTH)+maanedTaeller);
Calendar c = new GregorianCalendar(aar,maaned,1);
int dageMaaned = c.getActualMaximum(c.DAY_OF_MONTH);
int dageUge=0;
int dageUge2 = (c.get(c.DAY_OF_WEEK));
int ugeAar = c.get(c.WEEK_OF_YEAR);
SimpleDateFormat sdf = new SimpleDateFormat( "EEEE" );
String dagNavn = sdf.format( c.getTime());
if(dagNavn.equals("mandag")) dageUge=0;
if(dagNavn.equals("tirsdag")) dageUge=1;
if(dagNavn.equals("onsdag")) dageUge=2;
if(dagNavn.equals("torsdag")) dageUge=3;
if(dagNavn.equals("fredag")) dageUge=4;
if(dagNavn.equals("l�rdag")) dageUge=5;
if(dagNavn.equals("s�ndag")) dageUge=6;
System.out.println("maaned "+maaned);
System.out.println("uge dag "+dageUge);
System.out.println("uge dag "+dageUge2);
System.out.println("dage maaned "+dageMaaned);
System.out.println("dag navn "+dagNavn);
int taeller=1;
int taeller2=0;
for(int i=0;i<6;i++)
int ii = 0;
if(taeller2<dageUge)// MANDAG
data[ii] ="";
ii++;
if(taeller==dageMaaned)break;
taeller2++;
else
data[ii] =""+taeller;
ii++;
if(taeller==dageMaaned)break;
taeller++;
taeller2++;
if(taeller2<dageUge)// TIRSDAG
data[ii] ="";
ii++;
if(taeller==dageMaaned)break;
taeller2++;
else
data[ii] =""+taeller;
ii++;
if(taeller==dageMaaned)break;
taeller++;
taeller2++;
if(taeller2<dageUge)// ONSDAG
data[ii] ="";
ii++;
if(taeller==dageMaaned)break;
taeller2++;
else
data[ii] =""+taeller;
ii++;
if(taeller==dageMaaned)break;
taeller++;
taeller2++;
if(taeller2<dageUge)// TORSDAG
data[ii] ="";
ii++;
if(taeller==dageMaaned)break;
taeller2++;
else
data[ii] =""+taeller;
ii++;
if(taeller==dageMaaned)break;
taeller++;
taeller2++;
if(taeller2<dageUge)// FREDAG
data[ii] ="";
ii++;
if(taeller==dageMaaned)break;
taeller2++;
else
data[ii] =""+taeller;
ii++;
if(taeller==dageMaaned)break;
taeller++;
taeller2++;
if(taeller2<dageUge)// L�RDAG
data[ii] ="";
ii++;
if(taeller==dageMaaned)break;
taeller2++;
else
data[ii] =""+taeller;
ii++;
if(taeller==dageMaaned)break;
taeller++;
taeller2++;
if(taeller2<dageUge)// S�NDAG
data[ii] ="";
ii++;
if(taeller==dageMaaned)break;
taeller2++;
else
data[ii] =""+taeller;
ii++;
if(taeller==dageMaaned)break;
taeller++;
taeller2++;
for(int i=0;i<5;i++)
data[0] =""+ugeAar;
ugeAar++;
if(ugeAar==52)
ugeAar=1;
public int getColumnCount()
return columnNames.length;
public int getRowCount()
return data.length;
public String getColumnName(int col)
return columnNames[col];
public Object getValueAt(int row, int col)
return data[row][col];
public boolean isCellEditable(int row, int col)
return true;
public void setValueAt(Object value, int row, int col)
data[row][col] = value;
fireTableCellUpdated(row, col);
fireTableDataChanged();

First of all, since you post a lot of questions please learn how to use the forum correctly:
1) Don't cross post (http://forum.java.sun.com/thread.jsp?forum=31&thread=292582)
2) Use [ code ]...[ /code ] tags around you code so people can actually read the code.
The way I understand it, the fireTableDataChanged() method will invoke the getValueAt() method of your data model for every cell in your table.
Now for your problem. The reason nothing happens is because your data hasn't changed.
When you create MyTableModel the constructor populates your two dimensional 'data' array.
When the actionListener is invoked you change the variable 'maaned', but thats all you do, you don't reset the values of you data array. What you need to do is execute the code in your constructor, which will reset the values in your data array. (ie. the code in your constructor should be moved to a separate method so it can be executed by the constructor and the actionListener.
At least I think thats what the problem is. Hope that makes sense.

Similar Messages

  • Clear and update JTable.

    Hi. this is a follow up from [Original Tread in "New To Java"|http://forums.sun.com/thread.jspa?messageID=10886612&#65533;]
    Hope you can help me here. For you who dont read the link. This application is build only to lay up here. So the Layout aint pretty. It compiles and run tho. What i want and cant get to work is to reload table when i push my JTabbedPane.
    Main Class
    package test;
    import javax.swing.*;
    import javax.swing.event.*;
    public class Main {
        public Main() {
            run();
        public void run(){
         frame();
        // clear and update JTable in class three
        public void clearThree() {
            Three t = new Three();
             t.clearVector();
        public JFrame frame() {
            JFrame frame = new JFrame();
            JTabbedPane tab = new JTabbedPane();
            tab.addTab("two",new Two());
            tab.addTab("three", new Three());
            tab.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    clearThree();// this dont work
            frame.add(tab);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800,400);
             frame.setVisible(true);
             frame.pack();
            return frame;
        public static void main(String[] args) {
             java.awt.EventQueue.invokeLater(new Runnable() {
                         public void run(){
           new Main();
    }// class two
    package test;
    import java.awt.event.*;
    import java.util.Vector;
    import javax.swing.*;
    // class two&#347; only purpose is to  call clear() in class Three
    public class Two extends JPanel{
    public Two(){
    toolBar();
      public void clearThree () {
       Three t = new Three();
       t.clearVector();
      public void toolBar(){
      JToolBar bar = new JToolBar();
      JButton button = new JButton("clear");
      button.addActionListener(new ActionListener (){
          public void actionPerformed(ActionEvent e){
          clearThree(); // this dont work
    bar.add(button);
    add(bar);
    }// class three hold the table.
    package test;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Vector;
    import javax.swing.*;
    import javax.swing.table.DefaultTableModel;
    public class Three extends JPanel{ 
            DefaultTableModel model;
            JTable table;
            Vector v = new Vector();
            Vector a = new Vector();
            Vector<Vector> r = new Vector<Vector>();
        public Three() {
            jBar();
            jTable();
        public void clearVector(){
            v.removeAllElements();
            a.removeAllElements();
            r.removeAllElements();
            model.fireTableDataChanged();
        public void jBar() {
            JToolBar bar = new JToolBar();
            JButton button =  new JButton("clear");
            button.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    clearVector();// this does work
            bar.add(button);
            add(bar);
        public JScrollPane jTable(){
            v.addElement("ID");
            v.addElement("Name");
            a.addElement("01");
            a.addElement("Magnus");
            r.add(a);
            model = new DefaultTableModel(r,v);
            table = new JTable(model);
             JScrollPane pane = new JScrollPane(table);
             add(pane);
             return pane;
    }

    Thank you for your replay, I have taken all of your tips and modifed my original application. but the problem is still there. This has been a very messy thread. and it is becouse i thougth it were a table/model problem. But it&#347; not. In the code below I have a JTextField. When i push the JTabbedPanes i want the setText(); to kick in. this compile and run.
    // class One
    package test;
    import javax.swing.*;
    import javax.swing.event.*;
    public class Main {
        public Main() {
            run();
        public void run(){
         frame();
        public JFrame frame() {
            JTabbedPane tab = new JTabbedPane();
            final  Three t = new Three();
            JFrame frame = new JFrame();
            JPanel panel = new JPanel();
            tab.addTab("two",new Two());
            tab.addTab("three", new Three());
            tab.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                      t.setText(); // should call setText() in class Three.
            frame.add(panel);
            frame.add(tab);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(800,400);
             frame.setVisible(true);
             frame.pack();
            return frame;
        public static void main(String[] args) {
             java.awt.EventQueue.invokeLater(new Runnable() {
                         public void run(){
           new Main();
    }class Two. Does nothing more then holding an empty tab
    package test;
    import javax.swing.*;
    public class Two extends JPanel{
    public Two(){
    emptyPane();
      public void emptyPane () {
      JLabel  label = new JLabel("Just an empty JTabbedPane");
      add(label);
      }class Three
    package test;
    import javax.swing.*;
    public class Three extends JPanel{ 
             JTextField text;
        public Three() {
            text();
        public void setText() {
            text.setText("Hello"); // this piece of code i want to insert in my JTextField
            validate();                // when i push the JTabbedPanes.
            repaint();
            updateUI();
        public JTextField text(){
             JToolBar bar = new JToolBar();
            text = new JTextField("",20);
            bar.add(text);
            add(bar);
            return text;
    }

  • HT5052 hi , i cant update mi ipod touch software, a soon as the download process in finished an error message appears

    hi , i cant update mi ipod touch software, a soon as the download process in finished an error message appears :" session time has expired" something like that

    Disabling the computer's security software during the download and update usually resolves a network timeout error.

  • HT4972 i cant update my iphone 3gs to a more newer ios? it says here error! and the phone flashes some connect to itunes.. an if i connct nothing happens.. help me.. the ipgone wont open . and work pls help me thank you!

    i cant update my iphone 3gs to a more newer ios? it says here error! and the phone flashes some connect to itunes.. an if i connct nothing happens.. help me.. the ipgone wont open . and work pls help me thank you!

    Hello AlexCornejo,
    Thanks for using Apple Support Communities.
    The screen you're seeing on your iPhone indicates it is in recovery mode.  Now since the device is not appearing in iTunes on your PC, first follow the steps in this article:
    iOS: Device not recognized in iTunes for Windows
    http://support.apple.com/kb/TS1538
    After following those steps, you should be able to restore your iPhone.
    Take care,
    Alex H.

  • How can i remove my credit card from app store, the none option its not there and i don't Owen  nothing to apple, my last in app purchase was in clash of clans, please help!!! Because of that problem i cant update my apps! Plz help!!!!!

    How can i remove my credit card from app store, the none option its not there and i don't Owen  nothing to apple, my last in app purchase was in clash of clans, please help!!! Because of that problem i cant update my apps! Plz help!!!!!

    You've logged into your account and viewed your purchase history and there aren't any error messages shown (e.g. 'problem with a previous purchase'), and you haven't got any purchases due (e.g. pre-orders and/or subscriptions) : Why can’t I select None when I edit my Apple ID payment information ?

  • Cant update apps. asks for password for another account i had on a dell notebook. either i forgot the pass word or its not taking it. i can download apps,music with present mac note book but not apps. how can i update apps on my mac and iphone 4?

    cant update apps on my mac or iphone4. asks for password for another account i had on a dell notebook. either i forgot the pass word or its not taking it  . i can download apps and music.  how can i update apps on my mac and iphone 4?

    I had the same problem today and was able to resolve it without having to do a restore or reset. The problem had something to do with my mail accounts. The upgrade reset my mail settings, switching both my gmail and my .mac mail to "archive all mail". I went into the General Settings, disabled that setting, and resynced the phone. The "other" storage allottment dropped back down to less than a gig.
    Before you restore or reset, I would try that first.

  • My credit card was stolen,since i cancelled the card and waiting for a new one i cant update any of my apps because of the billing info is incorrect,how can i update without my new card?

    my credit card was stolen,since i cncelled and waiting for a replacement i cant update any apps or dl any apps because the billing info says its incorrect now,how can i update and dl while waiting for my new card?

    It would be best for you to open iTunes, sign in and view your account. If all the purchases were paid already instead of entering your new card information, it will give you an option for "NONE" as a payment method. Again this is not applicable of you have a pending charges with iTUnes

  • I cant update my ipod touch 2nd generation

    i cant update my ipod i have the most up to date i tuns but it wont let me up date my ipod from ios 2 to ios 4.2.3

    Verify you have a 2G and not a 1G. The 1G does not have volume buttons one the upper left edge and does not have an internal speaker
    To update
    The Settings>General>Software Update comes with iOS 5 and later.
    Connect the iPod to your computer and update via iTunes as far as your iPod model allows
    iOS: How to update your iPhone, iPad, or iPod touch
    A 1G iPod can go to iOS 2.2 via iTunes and iOS 3.1.3 via         
    Purchasing iOS 3.1 Software Update for iPod touch (1st generation)                   
    https://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/touchLegacyLandingPage
    - A 2G to 4.2.1. Requires iTunes version 10 or higher. If a Mac it requires OSX 10.5.8 or later.
    Identifying iPod models

  • Hi i have a ipod touch 4 generation 64gb and my camera is blocked and dose not work i cant update the ipod either

    hi i have a ipod touch 4 generation 64gb and my camera is blocked and dose not work i cant update the ipod either

    Try:
    - Reset the iOS device. Nothing will be lost       
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                                
    iOS: How to back up                                                                                     
    - Restore to factory settings/new iOS device.             
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
      Apple Retail Store - Genius Bar

  • I have a big problem :( why is it i cant update my ipod touch 2g into ios 4! im using the latest version of itunes and everytime i click "update" it stucks on the "contacting server" please help :( i want to update it now

    i have a big problem why is it i cant update my ipod touch 2g into ios 4! im using the latest version of itunes and everytime i click "update" it stucks on the "contacting server" please help i want to update it now

    Maybe here:
    iTunes for Windows: iTunes cannot contact the iPhone, iPad, or iPod software update server

  • Hi i cant update mi ipod touch its saids that the version 4.2.1 its the current version any tip ? thanks

    Hi i cant update mi ipod touch its saids that the version 4.2.1 its the current version any tip ? thanks

    if your ipod has only 8GB then it is an icompatible old model ( 2nd generation iPod ).
    IoS 4.2.1 on it indicates that it is a too old model.
    Only 3rd and 4th generation can be upgraded to iOS5.

  • I cant update ,y ipod touch 4 , i tried everything but it keep giving me error 3194, i cant update ,y ipod touch 4 , i tried everything but it keep giving me error 3194

    i cant update ,y ipod touch 4 , i tried everything but it keep giving me error 3194, i cant update ,y ipod touch 4 , i tried everything but it keep giving me error 3194

    Did you try the actions specified here:
    - iTunes: Specific update-and-restore error messages and advanced troubleshooting
    - 3194-How do I reset the hosts file back to the default?
    - http://support.apple.com/kb/ts1275
    Saying "i tried everything " provides us with no information as to what you arelady tried?

  • Cant update my ipod error 3194, cant update my ipod error 3194

    cant update my ipod error 3194, cant update my ipod error 3194

    Error 3194: Resolve error 3194 by updating to the latest version of iTunes. "For more Error 3194 steps see: This device is not eligible for the requested build above.
    If you're still having issues feel free to check out this useful KB article: http://support.apple.com/kb/ts1275

  • Cant update in ipod touch why???

    why i cant update all of my application in my ipod touch? when i go to updates tab theres a massage saying that there is no internet connection same in featured tab, but when i go to top 25 tab there is a connection why??plss help

    Maybe these discussions:
    App Store Updates (but only Updates)...: Apple Support Communities
    Apps suddenly don't update: Apple Support Communities

  • I changed internet providers forcing a change for my apple id but now I cant update because old id pops up asking for password which no longer valid

    I have an ipod and had to change my internet provider. because my previous apple id was part of that providers email I had to change my apple id. Since that time I cant update my ipod because it pops up with the old apple id and password which is no longer valid. How can I get the old apple id/password off the ipod and update my apps

    Hey cxl1234,
    Thanks for the question. I understand you are experiencing issues after changing your Apple ID. To troubleshoot the issue, lets do the following:
    App Store
    iOS 6 and later: Go to Settings > iTunes & App Store.
    - If you signed out before changing your Apple ID, sign in with your current Apple ID.
    - If you're still signed in with your previous Apple ID, tap your previous Apple ID and tap Sign Out. Then enter your current Apple ID to sign in.
    via Apple ID: What to do after you change your Apple ID
    http://support.apple.com/kb/HT5796
    If the above did not resolve your issue, and the applications are available from your purchase history, let’s go ahead and delete them and re-download (this will download the latest version):
    Downloading past purchases from the App Store, iBookstore, and iTunes Store
    http://support.apple.com/kb/HT2519
    Thanks,
    Matt M.

Maybe you are looking for

  • How do I save a clipping path in Photoshop so that Quark gives me the option to change the path opti

    I created a clipping path on a photo, clipping out a person's head so that I can have the person's head show up over the masthead on a cover. But when I save the photo in Photoshop and then import it into Quark, the option where it says I can change

  • Ipod Touch (First Generation) Wont sync to Itunes

    My Ipod touch 1st generation wont sync with Itunes but it is recognized on the computer i have the 2.1 software. i havent synced my ipod to this computer for probably three months becuase i usually sync it at my dads house. THANKS!!

  • Question on code in swing?

    Hey guys, I'm really new to Java. I was working on a bit of code to simply put up an oval and a rectangle in swing/awt. I was wondering if you guys could explain the concept of getContentPane().add(new MyComp()); I really don't get it. I will give yo

  • Best way to connect my iPod to my car stereo?

    My iTrip is a joke. What works best when wanting to connect my iPod directly to my car stereo when I must use the CD changer plug-in behind the stereo?

  • Condition base value in rebates

    Hi, I am developing a rebate report to list all rebates along with condition base value,scae base value and accruals. would you please let me know how to calculate these values as this values are not available in tables straight away. let me know Fun