Trying to update a JTable w/ new info

I've had some issue understanding the change events in the tutorial found here. http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#simple I've mostly gotten it, with the exception that my data does not change. I'm fairly certain it has to do with the tableChanged method. As always any help is GREATLY appreciated thanks.
This is a simple JFrame containing a Table with a JButton that changes the value of my data variable.
The tableChanged method is basically straight copied, what do I need to do for the entire table to update?
package testtable;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import java.awt.Dimension;
import java.awt.BorderLayout;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import javax.swing.event.TableModelListener;
import javax.swing.event.TableModelEvent;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
* @author rico
public class TestTable implements TableModelListener {
    //this method is verbatim out of the tutorial
    public void tableChanged(TableModelEvent e) {
        int row = e.getFirstRow();
        int column = e.getColumn();
        TableModel model1 = (TableModel)e.getSource();
        String columnName = model.getColumnName(column);
        Object data3 = model.getValueAt(row, column);
        // Do something with the data...
        static String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
        static Object[][] data = {
            {"Mary", "Campione",
             "Snowboarding", new Integer(5), new Boolean(false)},
            {"Alison", "Huml",
             "Rowing", new Integer(3), new Boolean(true)},
            {"Kathy", "Walrath",
             "Knitting", new Integer(2), new Boolean(false)},
            {"Sharon", "Zakhour",
             "Speed reading", new Integer(20), new Boolean(true)},
            {"Philip", "Milne",
             "Pool", new Integer(10), new Boolean(false)}
        static Object[][] data2 = {
            {"Cunt", "Campione",
             "Snowboarding", new Integer(5), new Boolean(false)},
            {"Alison", "Huml",
             "Rowing", new Integer(3), new Boolean(true)},
            {"Kathy", "Walrath",
             "muff-diving", new Integer(2), new Boolean(false)},
            {"Sharon", "Zakhour",
             "Motor_boating", new Integer(20), new Boolean(true)},
            {"Philip", "Milne",
             "Pool", new Integer(10), new Boolean(false)}
        static AbstractTableModel model = new AbstractTableModel() {
            public Object getValueAt(int row, int col) {
                return data[row][col];
            public int getColumnCount() {
                return columnNames.length;
            public int getRowCount() {
                return data.length;
            @Override
            public void setValueAt(Object value, int row, int col) {
                data[row][col] = value;
                fireTableDataChanged();
     * @param args the command line arguments
    public static void main(String[] args) {
        JFrame frame = new JFrame("TestTable");
        frame.setSize(500, 500);
        JButton button = new JButton("button");
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                data = data2;
        JTable table = new JTable(model);
        table.getModel().addTableModelListener(table);
        JScrollPane pane = new JScrollPane(table);
        pane.setPreferredSize(new Dimension(400, 200));
        frame.add(pane, BorderLayout.NORTH);
        frame.add(button, BorderLayout.SOUTH);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
}Edited by: rico16135 on Aug 30, 2008 4:13 AM

There is no need to extend AbstractTableModel in this example.
You can just create a DefaultTableModel using data and columnNames.
If you want to display data2 inside the table create a new DefaultTableModel with data2 and use table.setModel to update the table.

Similar Messages

  • HT2404 I'm trying to update apps and download new ones on mi ipad, but it doesn't work... the icons say "waiting" and nothing happens for days!

    I'm trying to update apps and download new ones on mi ipad, but it doesn't work... the icons say "waiting" and nothing happens for days!Help!

    Here are a bunch of things that you can try to get the downloads to resume.
    Reboot the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons.
    Make sure that you do not have a stalled download in iTunes - a song or podcast .... if you have a download in there that did not finish, complete that one first. Only one thing can download at a time on the iPad so that could be what is causing the problem.
    If that doesn't work - sign out of your account, restart the iPad and then sign in again.
    Settings>iTunes & App Store>Apple ID. Tap your ID and sign out. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Go back to Settings>iTunes & App Store>Sign in and then try to update again. Tap one waiting icon only if necessary to start the download stream.
    You can also try deleting the waiting icons - tap and hold down on an icon until it wiggles - the tap the X on the icon to delete it. Then try to download again.
    You can try resetting all settings. Settings>General>Reset>Reset All Settings. You will have to enter all of your app preferences and device settings again.
    If all else fails, download the updates or the apps in iTunes on your computer and then sync the content to your iPad.

  • I am trying to update i Tunes to new version i get a message saying iTunes has an invalid signature and will not install.Any help please.

    I am trying to update iTunes to new version .
    When it goes to install i get a message saying iTunes has an invalid signature and will not install.
    Any help please.

    Go directly to Apple link to download
    http://support.apple.com/kb/DL1426
    Select "Save" instead of "Run".  Once downloaded, double click the iTunesetup.exe to install.

  • HT4623 i tried to update my phone to new software and there is no button that says software update so now what do i need to do?

    I have tried to update my iphone 3g with new software and i cant do it. i need help. i cant find the software and i cant do it thru my itunes or my phone

    You update the iOS using iTunes
    If you have an iPhone 3G you can only update to 4.2.1
    if you have an iPhone 3GS you can update to 6.1.3
    http://support.apple.com/kb/HT4623

  • Trying to update iphone with the new software. being told cannot do adn to check network settings

    Trying to update iphone. getting an error message to check network settings.  I dont know what to do. have wireless router.

    This is asked and answered every day, several times.  The forum search bar is on the right side of this page.
    Disable your firewall/seurity software  and try again.

  • How do i update a JTable with new data?

    Hey
    I have a JTable where the data of some football players are shown. Name, club, matches and goals. What i want is to change the data in
    the JTable when i click a button. For example each team in a league has its own button, so when i click the teams button, JTable has
    data of that teams players.
    Here is the code i have atm, there isnt anything on how to change the data, because i dont know where to start, plz point me in somekind of direction:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package test;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.JMenuBar;
    import javax.swing.ImageIcon;
    import javax.swing.JTable;
    import javax.swing.JButton;
    import javax.swing.JTextArea;
    import javax.swing.JScrollPane;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    * @author Jesper
    public class Main extends JFrame implements ActionListener {
        private Players players;
        private JTextArea output;
        private JScrollPane scrollPane2;
        private JButton button1, button2;
        private String newline = "\n";
        private int club = 1;
        public Main(){
            players = new Players();
        public JMenuBar createMenuBar(){
            JMenuBar menuBar = new JMenuBar();
            JMenu menu = new JMenu("File");
            menu.setMnemonic(KeyEvent.VK_A);
            menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items");
            menuBar.add(menu);
            // add menuitems/buttons
            JMenuItem menuItemNew   = new JMenuItem("new");
            menuItemNew.setActionCommand("1");
            menuItemNew.addActionListener(this);       
            JMenuItem menuItemOpen   = new JMenuItem("Open");
            JMenuItem menuItemQuit   = new JMenuItem("Quit");
            menuItemQuit.setActionCommand("2");
            menuItemQuit.addActionListener(this);
            // add to menu
            menu.add(menuItemNew);
            menu.add(menuItemOpen);
            menu.add(menuItemQuit);
            return menuBar;
        public void actionPerformed(ActionEvent e){
            String s;
            if ("Silkeborg IF".equals(e.getActionCommand())){
                club = 1;
                s = e.getActionCommand();
                output.append(s + newline);
                button1.setEnabled(false);
                button2.setEnabled(true);
            } else{
                club = 2;
                s = e.getActionCommand();
                output.append(s + newline);
                button1.setEnabled(true);
                button2.setEnabled(false);
        //Quit the application.
        protected void quit() {
            System.exit(0);
        public Container createContent(){
            JPanel contentPane = new JPanel(new GridLayout(3,1));
            ImageIcon icon = createImageIcon("middle.gif", "a pretty but meaningless splat");
            JTable table = new JTable(players.showPlayers(club));
            //Create the first label.
            button1 = new JButton("Silkeborg IF");
            button1.setToolTipText("Klik her for at se Silkeborg IF");
            button1.addActionListener(this);
            button1.setActionCommand("Silkeborg IF");
            //Create the second label.
            button2 = new JButton("FC Midtjylland");
            button2.setToolTipText("Klik her for at se FC Midtjylland");
            button2.addActionListener(this);
            button2.setActionCommand("FC Midtjylland");
            //Create a scrolled text area.
            output = new JTextArea(5, 30);
            output.setEditable(false);
            scrollPane2 = new JScrollPane(output);
            //Add stuff to contentPane.
            contentPane.add(button1);
            contentPane.add(button2);
            contentPane.add(table);
            contentPane.add(scrollPane2, BorderLayout.CENTER);
            return contentPane;
        protected static ImageIcon createImageIcon(String path,
                                                   String description) {
            java.net.URL imgURL = Main.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL, description);
            } else {
                System.err.println("Couldn't find file: " + path);
                return null;
        public static void createGUI(){
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            Main main = new Main();
            frame.setJMenuBar(main.createMenuBar());
            frame.setContentPane(main.createContent());
            frame.setSize(500, 500);
            frame.setVisible(true);
         * @param args the command line arguments
        public static void main(String[] args) {
            createGUI();
    }

    ooohh sorry... i posted the wrong code :S
    Here is the correct code:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package test;
    import java.util.HashMap;
    import java.util.Set;
    import javax.swing.table.*;
    * @author Jesper
    public class Players {
        HashMap<Player, Stats> players;
        public Players(){
            players = new HashMap<Player, Stats>();
            addPlayer();
        public void addPlayer(){
            //Silkeborg IF
            players.put(new Player("Martin ?rnskov", 1), new Stats(19, 3, 1));
            players.put(new Player("Thomas Raun", 1), new Stats(23, 6, 0));
            players.put(new Player("Jimmy Mayasi", 1), new Stats(26, 26, 3));
            players.put(new Player("Lasse J?rgensen", 1), new Stats(33, 0, 0));
            //FC Midtjylland
            players.put(new Player("Frank Kristensen", 2), new Stats(19, 3, 1));
            players.put(new Player("Thomas R?ll", 2), new Stats(23, 6, 0));
            players.put(new Player("Simon Poulsen", 2), new Stats(26, 26, 3));
            players.put(new Player("Magnus Troels", 2), new Stats(33, 0, 0));
        public DefaultTableModel showPlayers(int club){
            String[] columNames = {"Spiller", "Klub", "Kampe", "M?l", "R?de kort"};
            //Object[][] data = {{"Martin ?rnskov", 19, 3, 1}, {"Thomas Raun", 23, 6, 0}};
            Set<Player> keys = players.keySet();
            Object[][] data = new Object[keys.size()][columNames.length];
            int i = 0;
            for(Player player : keys){
               if(player.getClub() == club){
                   data[0] = player.getName();
    data[i][1] = player.getClub();
    data[i][2] = players.get(player).getMatches();
    data[i][3] = players.get(player).getGoals();
    data[i][4] = players.get(player).getRedCards();
    i++;
    DefaultTableModel table = new DefaultTableModel(data, columNames);
    return table;

  • Error while trying to update my Ipad for new iOS5 :(

    On trying to update to the lastest iOs5 version for my Ipad, after syncing everything correctly, a last pop-up shows " Error occured while backing up Ipad (-37) Continue will result in lost of all contents of Ipad"...what do i need to do or fix!? Help please!!

    i have tried this a couple of times already and it also would show " error... (-5000) , but it says the same thing only difference is the error number. Please help!!!

  • Tried to update iPod, failed, no new drivers installed. Now iPod does not show in my computer or in iTunes.

    Anyone know how I can update/unbrick this iPod? It's useless. It's stuck on the screen that says connect to iTunes. iTunes doesn't know it's there. My computer doesn't know it's there. It's not the USB port.
    Please don't direct me here - http://support.apple.com/kb/HT1808 - already tried, no results.
    Last time it was a missing driver for iTunes but iTunes says nothing new is needed. Help appreciated.

    Let me try this again. My computer said my iPod needed an update. I clicked ok. iTunes said it was doing the update. I browsed the internet. I came back to it after it was done, and it said update failed, no new drivers installed. Now my iPod touch is a brick. I cannot use it for anything. You know that screen that shows the usb cable, a white arrow, and iTunes? It's stuck there. No amount of pushing the sleep/wake button and home button will convince it to go to any other screen. When I go to 'My Computer', it does not recognize that there is anything there. It is not the USB port. Everything was fine until the update tried and failed.
    I am not installing iTunes (piece of crap software that it is) on the other computer in my apartment.
    I have exhausted the articles that sort of go with the problems I am having. They all assume a non brick iPod. Mine is a brick and therefore those articles, including the one you linked, are not relevant.
    Not meaning to be rude, but I came into this not caring much for Apple's business model. I've had my iPod for .. a week? Maybe two, and nothing I've seen has convinced me to feel otherwise. Apple's products are supposed to just work. I am not finding that to be the case. Anyone with anything helpful please?

  • Trying to update my auto recharge credit info

    My credit card for auto recharge has expired and I want to update my file with the new information.  The credit card number has changed and my account will not allow me to make the necessary changes.  I add as per the instructions and then it reverts back to the old account as if unsaved.  Can I just get someone there to add it for me?  Is there someone I can call instead of doing it online?

    Well, today my tools are going to be deactivated because my account is expiring.
    Still no solution or feedback on the status of the issue relating to the fact that my valid credit card is stuck in a processing limbo in their payment system.
    The biggest lesson learned is that subscription software & cloud based services are too risky for a professional production pipeline.
    Imagine if I had employees and a huge deadline this week, I would have to explain to my clients that the reason I can't deliver is because Adobe can't process my credit card for whatever reason, and they deactivated my tools.
    Now, I probably won't be able to work today but at least this situation as forced me to re-evaluate how I'm going to build my new workflows and those of my clients.
    I was actually planning to convert my video production pipeline to Adobe Premiere but now, it's guaranteed I'm staying with Final Cut.
    Same thing for my photo retouching & motion workflows, I'm stripping out every Adobe Cloud tool from it.

  • Trying to update my account with new email address.

    My original account details I put in the wrong (non existent) email address.
    Problem is appears I have since already setup a new account with new email address from my iphone. 
    Now verification emails are being sent to non existnet email address and I can't change itunes account on laptop.

    Did you update your old iTunes account or create a new one ? If you updated the old one then try logging out of your account by tapping on your id in Settings > Store and then log back in and see if that 'refreshes' the account on the iPad. If you created a new account then you will need to continue to use the old account to download updates to its apps (or to redownload its content) - content is tied to the account that bought/downloaded it and it can't be transferred to a different account.

  • "Cannot connect to itunes store" error when trying to update or downloading a new app

    It's been like this for weeks and im really tired now. I tried all the fixed like reset networks, change the time, resetting my phone but none of them worked. Can someone please help me :(

    No solution??? please help

  • Trying to update software & sync on new computer

    i have ipod touch which was originally synced on computer at home, which is now defunct. I wish to sync with work computer which already had music mp3s stored on it. i have downloaded itunes onto my work computer and connected ipod. i wish to update the software from 3.1.3 to 4.2 but get a message saying there are items that need adding to your library and i should transfere before updating, if i ask it to comtinue it says all media will be deleted from this ipod.
    if i try to sync my music it tells me that all existing tracks on my ipod will be replaced by music in my library.
    in short i cant update without a sync, and i cant sync without losing all my music on the ipod.
    any ideas, many thanks. PS im not a tekkie im a grandad so plain speak please.

    Hi,
    See these easy to follow Support Links for what you need to do:
    Syncing with iTunes
    How to transfer or sync content to your computer
    Transferring purchases from your iPhone, iPad, or iPod to a computer
    Backing up, updating, and restoring your iPhone, iPad, or iPod touch software
    From Here:
    http://www.apple.com/support/ipodtouch/syncing/
    Cheers,  

  • Was renting on a monthly basis and got a message to update. tried to update and it failed. new message said to uninstall. Uninstalled and could not reinstall. went back to original and reinstalled off the trial page. Do I now have 2 rentals?

    Sorry about the length of the title of this thread. Thought I was already in discussion mode.
    Anyway as above I had a heck of a time getting anywhere on the website that would just let me reinstall.And of course no way to talk to a live person.
    Need to find out the status of my rental. Do I just cancel everything and start over? Very frustrating.

    You can check the status of your rental with the My account stuff on Adobe's site. Make sure to sign in using the demo so it can apply your license.

  • How can I get Firefox to stop trying to update to newer version

    I don't want a newer version of Firefox and I'm tired of it always trying to update automatically to a newer version. When this happens, I can't get to the website I want. This has to stop, or I'm going back to Windows Explorer.

    You can find the update settings here:
    *Tools > Options > Advanced > Update: "Automatically check for updates":
    If files already have been downloaded then you need to remove the files in the updates and updates\0 folder.
    You can delete active-update.xml and updates.xml as well if present.
    C:\Users\&lt;user&gt;\AppData\Local\Mozilla\Firefox\Mozilla Firefox\updates
    (%LOCALAPPDATA%\Mozilla\Firefox\Mozilla Firefox)

  • HT4623 Hi, every body please help trying to update my I pad with new iOS but there is no soft wear update tab what I am doing wrong

    Hi,
         all trying to update my iPad with new iOS but when in the settings tab there is no software update tab
    What I am doing wrong please or i,m going to throw it

    The Settings > General > Software Update option only appears when you have iOS 5+ installed, if you have iOS 4 then you will need to do the update via your computer's iTunes as described half-way down the page that you posted from.
    Connect the iPad to your computer's iTunes and copy any purchases off the iPad to your computer via File > Transfer Purchases (File > Devices > Transfer Purchases on iTunes 11). You may also want to copy photos and any important documents off the iPad as well e.g. via the file sharing section at the bottom of the device's apps tab when connected to iTunes, via wifi, email, dropbox etc - they should be included in the backup, but it's best to have a copy of them outside of the backup just in case. You can then force a backup of the iPad by right-clicking the iPad 'Device' on the left-hand sidebar of iTunes and selecting 'Backup' (on iTunes 11 you can enable the left-hand sidebar via option-command-S on a Mac, control-S on a PC)
    Then start the update by selecting the iPad on the left-hand sidebar, and on the Summary tab on the right-hand side clicking the Check For Updates button
    Updating to iOS 5+ : http://support.apple.com/kb/HT4972
    A first gen iPad will be updated to iOS 5.1.1, and an iPad 2 and 3 to iOS 6.1.3

Maybe you are looking for

  • Can't see data in InfoSet

    All, I'm having an issue with several InfoSets that I created. When I first created the InfoSets I was able to view data with not problem. But now that I've loaded some new data and in some cases completely reloaded all of the data to my InfoProvider

  • Calendar displays 24 hours versus 12 hours

    I somehow inadvertinly changed my daily and weekly calendar display to 24 hours.  In day or week view, there are 24 hour segments.  Does anyone know how to change back to a 12 hour display?

  • But I can not download adobe photoshop elements 11 when I want then get AUTOMATIC elements 12?

    but I can not download adobe photoshop elements 11 when I want then get AUTOMATIC elements 12?

  • Opening a link in new browser- JEditorPane

    Hello all, I am facing a small problem. I am loading an html file from local system in an JEditorPane. Now that html is having some links. Is there any way out by which that link when clicked is open into browser. Any idea is welcome. Smiles,

  • Gray screen

    product  number  b5s12ua#aba model dv67029wm windows 7 I was on the computer doing some work, and the internet wasnt responding. the computer completely froze so I turned it off without shutting it down, since it didnt respond. when I turn on on safe