Refreshing AbstractTableModel from different class...

Hi there ppl
Anybody know how to call:
model.fireTableStructureChanged()
from a different class? when i try i get a compiler error saying that i cannot reference a non-static variable from a staic content.
the first jframe holds a jtable that displays the model which consists of data from a db. the second jframe (which resides in another class) has a jtextfield which when submitted will update the db, therefore the db results need to be updated and then the model needs to be updated via
model.fireTableStructureChanged()
but from a different class. Is this possible and if so can somebody explain to me how?
Thanks fellow Javites.

Thanks for replying...
The TrainServiceFrame.updateStationTable() exists within the TrainServiceFrame class and is intended to update the stationModel object when called from another class (which will be the NewTrainStationFrame class).
<code>
     public static void updateStationTable() {
          stationModel.fireTableStructureChanged();          
</code>
The second code fragement is from the second class NewTrainStationFrame (which is not a subclass) which contains a jframe, jtextfield and a button. the method call to the stationModel(stationModel = AbstractTableModel) is done via: TrainServiceFrame.updateStationTable() when the submit button is clicked sending the string to a method ( addNewStation(newStation); )which updates the db.
<code>
button.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
                    newStation = newStationField.getText();
                    addNewStation(newStation);
// this would retrieve the updated db results + store in a TreeSet object
// TrainServiceFrame.getTrainStations();
                    TrainServiceFrame.updateStationTable();
</code>
I have just noticed something that is missing which when attempted to fix resulted in the same problem. there should also be a method called to retrieve the updated db, but as this is from a static context yet again i fall into the same ditch as the variables that store these db results are non-static and exist within the TrainStationFrame class.
Is the solution simply to change these relevent variables and methods that are to be called from another class, so that they are all static?

Similar Messages

  • How to access form objects from different class?

    Hello, I am new to java and i started with netbeans 6 beta,
    when i create java form application from template i get 2 classes one ends with APP and one with VIEW,
    i put for example jTextField1 with the form designer to the form and i can manipulate it's contents easily from within it's class (let's say it is MyAppView).
    Question>
    How can i access jTextField1 value from different class that i created in the same project?
    please help. and sorry for such newbie question.
    Thanks Mike

    hmm now it says
    non static variable jTree1 can not be referenced from static context
    My code in ClasWithFormObjects is
    public static void setTreeModel (DefaultMutableTreeNode treemodel){
    jTree1.setModel(new DefaultTreeModel(treemodel));
    and in Class2 it is
    ClasWithFormObjects.setTreeModel(model);

  • Access oracle database from different classes in desktop / standalone app.

    I am a bit confused as to what way to go. I am building a desktop application that needs to access an oracle database. I have done this in the past using code similar to the following:
            try {             DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());             Connection conn = DriverManager.getConnection(                     "jdbc:oracle:thin:@111.111.111.111:oracledb",                     "username", "password" );             // Create a Statement             Statement stmt = conn.createStatement();             ResultSet rs = stmt.executeQuery(                     "select ... from ...");             while (rs.next()) {                 ReportNumberCombo.addItem(rs.getString(1));             } // end of rs while             conn.close();         } //  end of try         catch( Exception e ) {             e.printStackTrace();         }
    The problem I would like to resolve is that I have this code all over the place in my application. I would like to have it in one objects method that i can call from other classes. I can't easily see how to do this, or maybe at this point I'm just too confused.
    I want to be able to change this connection info from a properties file which I have already done, not sure if this bit of information would change the answer to my question. I was also looking at the DataSource api, this looks like it is close to what I should use, what are your thoughts?
    I would also like to if JNDI is only for web applications or would be appropriate for a desktop app.
    Thank you for your help, I realize this is all over the place but I really need these topics cleared up!

    I have tried exactly that and am getting an error which let me to believe it couldn't be done that way. Here is my code and error message:
    public class readPropsFile {
        String getURL() throws IOException {
            // default values for properties file
            String Family = "Family:jdbc" + ":oracle:" + "thin:@";
            String Server = "Server:111.111.111.111";
            String Port = "Port:1521";
            String Host = "Host:oradb";
            String Username = "Username:username";
            String Password = "Password:password";
            try {          
                new BufferedReader(new FileReader("C:\\data\\Properties.txt"));
            } catch (FileNotFoundException filenotfound) {
                System.out.println("Error: " + filenotfound.getMessage());
                // displays to console if file DOES NOT exist
                System.out.println("The file DOES NOT exist, now creating...");
                FileWriter fileObject = null;
                fileObject = new FileWriter("c:\\data\\Properties.txt");
                BufferedWriter out = new BufferedWriter(fileObject);
                // writes to output as simple text.
                out.write(Family);
                out.newLine();
                out.write(Server);
                out.newLine();
                out.write(Port);
                out.newLine();
                out.write(Host);
                out.newLine();
                out.write(Username);
                out.newLine();
                out.write(Password);
                out.newLine();
                out.close();
            // displays to console if file exists
            System.out.println("The file exists, or was created sucessfully");
    //      creates the properties object, assigns text file.
            Properties props = new Properties();
            FileInputStream in = new FileInputStream("c:\\data\\Properties.txt");
            props.load(in);
            Family = props.getProperty("Family");
            Server = props.getProperty("Server");
            Port = props.getProperty("Port");
            Host = props.getProperty("Host");
            Username = props.getProperty("Username");
            Password = props.getProperty("Password");
    //      prints properties to a file for troubleshooting
            PrintStream s = new PrintStream("c:\\data\\list.txt");
            props.list(s);
            in.close();
            String URL = "\"" + Family + Server + ":" + Port + ":" + Host + "\"" +
                    "," + "\"" + Username + "\"" + "," + "\"" + Password + "\"";
            System.out.println("This is the URL:" + URL);
            return URL;
    }And here is where I try to call the method:
    public class connWithProps1 {
        public static void main(String[] args) {
            readPropsFile callProps = new readPropsFile();
            try {
                callProps.getURL();
                String url = callProps.getURL(); // not needed
                System.out.println("The URL (in connWithProps1) is: " + csoProps.getURL());
                DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
                Connection conn = DriverManager.getConnection(url);
                // Create a Statement
                Statement stmt = conn.createStatement();
                ResultSet rs = stmt.executeQuery("select .... WHERE ....'");
                while (rs.next()) {
                    System.out.println(rs.getString(1));
                } // end of rs while
                conn.close();
            } catch (SQLException sqle) {
                Logger.getLogger(connWithProps1.class.getName()).log(Level.SEVERE, null, sqle);
            } catch (IOException ioe) {
                Logger.getLogger(connWithProps1.class.getName()).log(Level.SEVERE, null, ioe);
    }The error I get is:
    SEVERE: null
    java.sql.SQLException: Listener refused the connection with the following error:
    ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
    The Connection descriptor used by the client was:
    111.111.111.111:1521:oradb","username","password"
            at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
            at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:112)
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:173)
            at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:460)
            at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:411)
            at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:490)
            at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:202)
            at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
            at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:474)
    {code}
    Although the URL prints out correctly and when I tried plugging in the URL manually, it works just fine. One other thing I noticed was the line "The file exists, or was created sucessfully" is output 3 times.
    I will go back and change my code to properly close the resultset, thanks for catching that. Id rather use what I have instead of JNDI unless it's nesessary.
    Edited by: shadow_coder on Jun 19, 2009 2:16 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How do I call methods with the same name from different classes

    I have a user class which needs to make calls to methods with the same name but to ojects of a different type.
    My User class will create an object of type MyDAO or of type RemoteDAO.
    The RemoteDAO class is simply a wrapper class around a MyDAO object type to allow a MyDAO object to be accessed remotely. Note the interface MyInterface which MyDAO must implement cannot throw RemoteExceptions.
    Problem is I have ended up with 2 identical User classes which only differ in the type of object they make calls to, method names and functionality are identical.
    Is there any way I can get around this problem?
    Thanks ... J
    My classes are defined as followes
    interface MyInterface{
         //Does not and CANNOT declare to throw any exceptions
        public String sayHello();
    class MyDAO implements MyInterface{
       public String sayHello(){
              return ("Hello from DAO");
    interface RemoteDAO extends java.rmi.Remote{
         public String sayHello() throws java.rmi.RemoteException;
    class RemoteDAOImpl extends UnicastRemoteObject implements RemoteDAO{
         MyDAO dao = new MyDAO();
        public String sayHello() throws java.rmi.RemoteException{
              return dao.sayHello();
    class User{
       //MyDAO dao = new MyDAO();
       //OR
       RemoteDAO dao = new RemoteDAO();
       public void callDAO(){
              try{
              System.out.println( dao.sayHello() );
              catch( Exception e ){
    }

    >
    That's only a good idea if the semantics of sayHello
    as defined in MyInterface suggest that a
    RemoteException could occur. If not, then you're
    designing the interface to suit the way the
    implementing classes will be written, which smells.
    :-)But in practice you can't make a call which can be handled either remotely or locally without, at some point, dealing with the RemoteException.
    Therefore either RemoteException must be part of the interface or (an this is probably more satisfactory) you don't use the remote interface directly, but MyInterface is implemented by a wrapper class which deals with the exception.

  • HOW: To save/refresh data from different forms but in same session

    Hi
    I have 2 screens
    Screen-1
         Tabluar form with 10 rows and each row corresponds to one edit image
    Screen-2
         Forms type form with multiple text items and list items and one OK and cancel button
         If I click on OK button, whatever I enter in screen-2 is updated but till now no commit only EXIT_FORM and the screen is going back to Screen-1
    In Screen-1 I have written trigger When-Wiindow-Activated, which has to refresh the screen-1 values with the changed values from above screen-2
    BUT this is not happening. (I am using SET_BLOCK_PROPERTY... and EXECUTE_QUERY to refresh, by passing the query string)
    Also I have one save button in Screen-2 which should commit whatever I have updated in Screen-2 (once or muyltiple times)
    I am opening the Screen-2 from Screen-1 by using OPEN_FORM built in with form name and ACTIVATE,NO_SESSION and also the parameter.
    Please let me know if I am doing any mistake in calling or some properties need to be set.
    I assume that, as the aplication is in the same session then the newly edited record in screen2 should get reflect in screen-1, and should get saved once I click on save button in screen-1 (FORMS_DDL('COMMIT'))
    regards
    JC

    I assume that Screen 2 is not based on table as it doesn't prompt you "Do you want to save chages" on exit.
    So you probably just updating with update statement.
    You will need to call POST; before exit_form in screen 2.
    Post;
    Exit_Form(NO_COMMIT, NO_ROLLBACK); Also in screen 1, instead of OPEN_FORM and re-query in WHEN-WINDOW-ACTIVATED, I would suggest to use call_form and re-query just after call_form:
       CALL_FORM('xxx',no_hide, no_replace, no_query_only, pl_id);
       SET_BLOCK_PROPERTY ('YOUR_BLOCK' ...
       GO_BLOCK('YOUR_BLOCK');
       EXECUTE_QUERY;

  • JTextarea from Different Class

    Hello, I have been searching through the forums for a while and cannot find a suitable answer.
    I have a main class that has a JTextArea which logs all the actions of the program, lets call it main. One of the actions that 'main' performs is to launch a seperate class called 'AdvancedMode' which inherits everything from 'main'. So 'Advanced mode' has its own seperate log in a JTextArea also, and what I want to do is to append the text from 'Advanced Mode's JTextArea to 'Mains's JTextArea when the exit button is clicked.
    I have tried several methods including a timer that appends it every 20 seconds but that doesnt work because it just repeats the text, also I tried making a class in 'Main' that is called when 'Advanced Mode' exits but I get a null pointer excpetion because 'main' is created in ActionPerformed.
    Has anyone got a simple solution to this (probably) simple question as it is driving me up the wall.
    I was going to post some code, but I doubt you need it
    Thanks in advance.

    Ok, doubt it will help but here goes
    This is from the 'Main' Class, when the Advanced Mode button is hit a new instance of it is created
            if(e.getActionCommand() == "Advanced Mode") {
                tt = new AdvancedMode();
                tt.init();
                tt.setVisible(true);
                textArea.append("Advanced Mode Accessed at " + te.easyDateFormat("HH:mm")+nl);
                check(tt);
            }...and this is where the 'Advanced Mode's JTextArea is declared and created
            //Creates the log for the MySql Command results
            area = new JTextArea();
            area.setEnabled(false);
            area.setDisabledTextColor(Color.BLUE);
            area.append("***************************" +nl);
            area.append("Log of SQL Commands and Errors" +nl);
            area.append("***************************" +nl);
            JScrollPane scrollPane = new JScrollPane(area);
            scrollPane.setBorder(BorderFactory.createTitledBorder(scrollPane.getBorder(),"MySQL Log",2,2,null,Color.BLUE));
            scrollPane.setPreferredSize(new Dimension(50, 100));...and here is where the 'AdvancedMode' class deals with exiting
            if(e.getActionCommand() == "Exit") {
                // Modal dialog with yes/no button
                String message = "Are you sure you wish to exit advanced mode?";
                int answer = JOptionPane.showConfirmDialog(frame, message);
                if (answer == JOptionPane.YES_OPTION) {
                        //check();
                    dispose();
                } else if (answer == JOptionPane.NO_OPTION || answer == JOptionPane.CANCEL_OPTION) {
                    // User clicked NO.
            }I want to append 'Main's' JTextArea with the contents of 'AdvancedMode's' JTextArea when the exit button is hit

  • Calling a method from different class

    Hey peeps,
    say i have a method in another class and i wish to call it, what would the code be for that?
    say for example the method was called createNewShoeBox and i was in another class?
    hope that makes sence

    jermaindefoe wrote:
    lol! id love to have one, and in which case would love to have the money for one as id definatley take it up,In the following part, you're saying you're a student. So there are peers you can ask, if not your professor. There are certainly also some who actualy know some programming and would teach you if you just asked them.
    im a first year student bear in mind though lol!!! and ma struggling, I see that, and the way you handle your problems, that won't change for the next few years.
    i may not be as good at java as you, but i can do other things better than you can, and thats life, we all have to start somewhereWhat you also can't do as well as I do is "realizing that using an internet forum is one of the worse ways to have people helping you to learn programming". You're lacking a lot of understanding for concepts where the label "basic" is almost exaggerating. I'm sure you can get that understanding, but being spoon-fed through a forum with no visible effort to figure things out is not the way to do it.

  • How to access a Stack class from different classes

    Hi
    I have a Stack implemented as Stack.java. I have 2 more java files Control.java and display.java.
    In Control.java
    I have created Stack stack = new Stack(); and am pushing values in the stack.
    In display.java i have some conditions where i want to push some values in the same stack as that on the Control.java.
    How do i acces the stack in Control.java from other files like display.java

    In display.java i have some conditions where i want
    to push some values in the same stack as that on the
    Control.java.
    How do i acces the stack in Control.java from other
    files like display.javaPass that object reference to some method. :-)

  • Load New JFrame from different class

    Hi, Im making an application that has a login jframe when it loads. If they login with the right info, I want the login jframe to dissapear, and I want the main menu jframe to open...
    The login jframe is: FearlessUI.java
    The menu jframe is MainMenu.java
    Anybody know the code to do so?

    Here is the code of MainMenu.java:
    * MainMenu.java
    * Created on December 19, 2006, 6:25 PM
    package my.FearlessForce;
    public class MainMenu extends javax.swing.JFrame {
        /** Creates new form MainMenu */
        public MainMenu() {
            initComponents();
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(0, 400, Short.MAX_VALUE)
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(0, 300, Short.MAX_VALUE)
            pack();
        }// </editor-fold>                       
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new MainMenu().setVisible(true);
        // Variables declaration - do not modify                    
        // End of variables declaration                  
    }

  • Updating Swing components from a different class

    I would like to use the JTextArea component in a JFrame to display fast updating text from my application. My application is very simple. When the app launches the GUI is created then my application engine would start processing and displaying text data into the GUI. After reading about Thread safety when using Swing components I concluded it would not be a good idea for my app engine class to update the JTextArea class directly using methods such as .append(String).
    I would be grateful for any suggestions on how I should approach updating Swing components from different classes.
    Many Thanks in advance Sean

    Hi
    Why don't you just implement a basic callback method?
    To do this the right way you should probably define a simple Interface that has a public method like updateProcessText(String s). Your swing class then implements this interface, basically forcing it to provide the public method you defined (this is no different than implementing ActionListener, which forces you to define actionPerformed). Secondly modify your processing class, so that it take's a class that implements the interface you just created, as one of the arguments in it's constructor. Lastly assign the argument from your construnctor to a private var - this will enable your processing class to have a handle to your swing class and update it as it pleases.
    This might sound very complex, but it's really simple once you've done it once.

  • Invoke a method in one class from a different class

    I am working on a much larger project, but to keep this simple, I wrote out a little test that would convey the over all theory of the program.
    What I am doing is starting out with a 2 JFrames and a Class. When the program is launched, the first JFrame opens. In this JFrame is a label and a button. When the button is clicked, the second JFrame opens. This JFrame has a textField and a button. The user puts the text in the textField and presses the button. When the button is pushed, I want the text that was just put in the textField, to be displayed in the first JFrame's label. I am trying to invoke a method in the first JFrame from the second, but nothing happens. I have also tried making the Class extend from JFrame1 and invoke it from there, but no luck. So, how do I invoke a method in a class from a different class?
    JFrame1 (I omitted the layout part. I made this in Netbeans so its pretty long)
    public class NewJFrame1 extends javax.swing.JFrame {
         private NewClass1 nC = new NewClass1();
         /** Creates new form NewJFrame1 */
         public NewJFrame1() {
              initComponents();
              jLabel1.setText("Chuck");
         public void setLabels()
              jLabel1.setText(nC.getName());
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         NewJFrame2 j2 = new NewJFrame2();
         j2.setVisible(true);The class
    public class NewClass1 {
         public static String name;
         public NewClass1()
         public NewClass1(String n)
              name = n;
         public String getName()
              return name;
         public void setName(String n)
              name = n;
    }The second jFrame
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                                  
         NewClass1 nC = new NewClass1();
         NewJFrame1 nF = new NewJFrame1();     
         nC.setName(jTextField1.getText());
         nF.setLabels();
         System.out.println(nC.getName());At this point I am begging for help. I have been trying for days to figure this out, and I just feel like I am not getting anywhere.
    Thanks

    So, how do I invoke a method in a class from a different class?Demo:
    public class Main {
        public static void main(String [] args) {
         Test1 t1 = new Test1();
         Test2 t2 = new Test2();
         int i = t1.method1();
         String s = t2.method2(i);
         System.out.println(s);
    class Test1 {
        public int method1() {
         return 10;
    class Test2 {
        public String method2(int i) {
         if (i == 10)
             return "ten";
         else
             return "nothing";
    }Output is "ten".
    Edited by: newark on May 28, 2008 10:55 AM

  • Why are these classes equal? Loaded from different classloaders.

    I thought that classes loaded from different classloaders were seen as different in the JVM? But this code prints true to every check:
    try
         Class c = new URLClassLoader( new URL[] { new URL( "jar:file://home/tests/test.jar!/" ) } ).loadClass( "Test" );
         Class c2 = new URLClassLoader( new URL[] { new URL( "jar:file://home/tests/test.jar!/" ) } ).loadClass( "Test" );
         System.out.println( ( c == c2 ) );
         System.out.println( ( c.equals( c2 ) ) );
         System.out.println( ( c.getName().equals( c2.getName() ) ) );
    catch (Exception e)
         e.printStackTrace();
    }

    DrClap wrote:
    The more unbelievable thing is that this:
    System.out.println( ( c == c2 ) );prints "true". That shouldn't happen, and it's nothing to do with facts about classloaders. It shouldn't happen because "new" called twice should produce two different objects, no matter what kind of objects they are.
    I didn't try your code because I would have had to spend a couple of minutes creating suitable jar files. But did you actually run that code? Or is it a reduction of some larger piece of code and you just assumed it would do what you said it does? Because I don't believe that.I actually ran the code and every line DID print out true. This is in Java 1.5.
    I figured out why they're all true though - it's because the jar file was in the classpath, so the classes were loaded by a different classloader (the same one). When I put the jar out of the classpath, the statments printed out like this:
    //false
    System.out.println( ( c == c2 ) );
    //false
    System.out.println( ( c.equals( c2 ) ) );
    //true
    System.out.println( ( c.getName().equals( c2.getName() ) ) );I agree on the first one printing true but I seem to remember something about how they changed that rule in Java 1.5. I could be wrong but in c++, that would be a completely valid true statement (assuming your class implemented the "==" operator), so maybe they changed it to be in line with that?

  • Updating Jlabel from a different class?

    Hi,
    Im in the middle of developing a program but swing is making it very hard for me to structure my code. The problem is I want to update the text of a Jlable from a different class when a button is pressed. THe event handling is done by a different class than the where the Jlabel is initiated which is why i think it doesnt work. But when the button is pressed it does execute a method from the main class that has the .setText() in it. Why wont the Jlabel update? Thank you

    Thanks for your help but i am still having trouble.
    This is the code from the button handler class
    public void actionPerformed(ActionEvent e)
           if ("btn3_sender".equals(e.getActionCommand()))
                JLabel j = temp2.getlblQuestion();
               j.setText("NEW TEXT");
           This is the code from the main class where the JLabel is created:
    public JLabel getlblQuestion()
        return lblQuestion;
    }How come this does not work??

  • Updating JPanel with buttons from a different class

    I have a JPanel in a class that has a gridlayout with buttons in it for a game board. And my problem is that when I want to update a button using setIcon() the button doesn't change in the GUI because the buttons are in a different class. The JPanel is in a Client class and the buttons are in a GamePlugin class. I've tried a bunch of different things but none of them worked or it was way too slow. I'm sure theres an easy way to do it that I'm not seeing. Any suggestions? Heres part of my code for updating the GUI.
    private JPanel boardPanel = new JPanel(); 
    Container cP = getContentPane();
    cP.add(boardPanel, BorderLayout.WEST);
    boardPanel.setPreferredSize(new Dimension(400, 400));
    boardPanel.setLayout(new GridLayout(8, 8));
    cP.add(optionsPanel, BorderLayout.CENTER);
          * Gets the board panel from the selected plugin.
         public void drawGameBoard(GamePlugin plugin) {
              board = (OthelloPlugin)plugin;
              boardPanel = board.getBoardPanel();
              for (int i = 0; i < GamePlugin.BOARD_SIZE; i++)
                   for (int j = 0; j < GamePlugin.BOARD_SIZE; j++) {
                        board.boardButtons[i][j].setActionCommand("" + i + "" + j);
                        board.boardButtons[i][j].addActionListener(this);
          * This method takes a GameBoard and uses it to update this class' data
          * and GUI representation of the board.
         public void updateBoard(GamePlugin updatedBoard) {
              board = (OthelloPlugin)updatedBoard;
              for (int i = 0; i < GamePlugin.BOARD_SIZE; i++) {
                   for (int j = 0; j < GamePlugin.BOARD_SIZE; j++) {
                        int cell = board.getCell(i,j);
                        if (cell == OthelloPlugin.PLAYER1){
                             board.boardButtons[i][j].setIcon(black);
                        else if (cell == OthelloPlugin.PLAYER2)
                             board.boardButtons[i][j].setIcon(white);
                        else
                             board.boardButtons[i][j].setText("");
         }

    txp200:
    I agree that a call to validate() , possibly repaint(), should fix your problem. In the class with the panel that the buttons are on, i would create a static repaint method that call panel.repaint(). You can then call that method in your other class. Just make sure u only use methods to change the properties of the button, never make a make a new one, as then you will lose the association with the panel. Hope this helps.
    -- Brady E

  • Executing a class from a class in different eclipse project.

    Consider the scenario:-
    I have 2 different projects in Eclipse
    project 1 and project2.There a class E.java in project1 which i want to execute from a class F.java which is in project2.Both the classes have the same hierarchy package structure in their respective projects.
    project1
    foo.hoo.E,java
    project2
    foo.hoo.F.java
    please advise me how can i execute E.java from F.java.
    .

    add the class files from project 1 to the classpath of project 2

Maybe you are looking for

  • How to read a .php file in flash

    Hi, Does anyone know if there's a possibility to read out a .php file in flash? (Like the iFrame in html) Some other webs showed me the 'loadvars' array.. Thanx!

  • Error in Build Applicatio​n (EXE)

    Hi, There is an error is prompt as attached when I was trying to build the exe. Both my Labview 2012 & Database toolkit are evaluation version. I have no idea how to choose the different option as the error message mentioned. Is there any alternative

  • Change PO while doing Goods Receipt

    Hi, We are getting GR data through inbound IDOC. We have a a requirement to change the PO while creating GR document. Scenario is like : We have ordered Material 'A' in the PO but we received an equivalent Material 'B'. So while processing the inboun

  • BI Content Install Simulation Issue

    Hi, I'm installing the technical content in BI 7.x SP15.    When I simulate I get all kinds of errors in the infocube section saying InfoObject xxxx  is not available in active version.   But when I check the list of collected objects the infoobjects

  • Error in loading iTunes 10.5 on my Mac

    I tried to upgrade to 10.5 last night and it seemed to go ok, but when i tired to open iTunes after the roboot i got the following message: The file "iTunes Library.itl" cannot be read because it was created by a newer version of itunes.  Would you l