Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / June 2004

Tip: Looking for answers? Try searching our database.

Can't update a JLabel from another Class

Thread view: 
ckroyer@comcast.net - 17 Jun 2004 03:59 GMT
Hi,

I'm a real rookie at programming so bear with me as I try to explain
my problem.

I have two classes, ClassA & ClassB. ClassB extends JPanel and ends up
being added to ClassA(the main application). Within ClassB are some
JPanels, JLabels etc.

I'm trying to change the text of one of the JLabels in ClassB by
pressing a button in ClassA. When I do this, the display appears to
shift slightly but nothing else happens. I can get the Jlabel text to
change by adding my updateData method to the ClassB constructor so I
know the updateData method itself is OK.

Here's the relevent code:

Action from ClassA (main application):

     else if (PLAY.equals(cmd)) { //Play button clicked
        myDataViewer.updateData();
     (FYI the else if statment works with other methods)

Method from ClassB (Component of ClassA):

    public void updateData() {
     latValue.setText("Help me");
    }

Thanks in advance for your help.
Roedy Green - 17 Jun 2004 04:04 GMT
>Action from ClassA (main application):
>
[quoted text clipped - 7 lines]
>     latValue.setText("Help me");
>    }

I see nothing wrong with the code you posted, except it is incomplete
and you violate coding conventions.

See http://mindprod.com/jgloss/codingconventions.html

Try posting your complete code.  The problem is likely somewhere else.

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Andrew Thompson - 17 Jun 2004 12:47 GMT
> Try posting your complete code...

For tips..
<http://www.physci.org/codes/sscce.jsp>

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

ckroyer@comcast.net - 18 Jun 2004 01:50 GMT
> > Try posting your complete code...
>
> For tips..
> <http://www.physci.org/codes/sscce.jsp>

Here's my code.

**********Main Application (ClassA)**********

/*
*
*/

import java.io.*;
import javax.swing.*;
import javax.swing.AbstractAction;
import javax.swing.Action;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;

import javax.swing.JMenuItem;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuBar;

import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import java.util.*;

import java.awt.*;
import java.awt.event.*;

import java.beans.beancontext.*;
import java.beans.*;

public class GPVLite extends JPanel implements ActionListener {
   protected JFormattedTextField GPSTextField, VidTextField;
   protected JFileChooser fchooser = new JFileChooser();
   protected JTextArea textArea;
   protected String newline = "\n";
   static final private String GPSFILE = "gpsfile";
   static final private String VIDFILE = "vidfile";
   static final private String GPVFILE = "gpvfile";
   static final private String PLAY = "play";
   static final private String STOP = "stop";
   static final private String PAUSE = "pause";
   static final private String NEWPOINTS = "new points";
   static final private String LAYERS = "layers";
   protected File gpsFile;
   static public DataViewer myDataViewer = new DataViewer();
   static public GpvData gpvdata;
   static public GPVLite myGpvl = new GPVLite();

   public GPVLite(){
       super(new BorderLayout());

     //create the window panes
     JSplitPane mainPane;
     JPanel gpsPanel, dataPanel;
     gpsPanel = new JPanel();
     dataPanel = new JPanel();
     dataPanel.setLayout(new BorderLayout());

     //Create DataViewer and put it into dataPanel
     //DataViewer myDataViewer = new DataViewer();
     myDataViewer.makeGUI();
     dataPanel.add(myDataViewer, BorderLayout.PAGE_END);   
 
     mainPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, dataPanel,
gpsPanel);
     mainPane.setOneTouchExpandable(false);
     mainPane.setDividerSize(5);
     mainPane.setDividerLocation(400);

     //Set minimum size of tabbed panels so split will slide correctly
     //Dimension minSize = new Dimension (0,0);
     //trainingPanel.setMinimumSize(minSize);

     //Set reSize weight so panes size properly when changing frame size
     mainPane.setResizeWeight(0.5);

       //Lay out the content pane.
       add(mainPane, BorderLayout.CENTER);

   }

//--------------------Create
MenuBar------------------------------------------

   public JMenuBar createMenuBar() {
       JMenuItem menuItem = null;
       JMenuBar menuBar;

       //Create the menu bar.
       menuBar = new JMenuBar();

       //Create the main menus.
       JMenu filesMenu = new JMenu("Files");
       JMenu controlsMenu = new JMenu("Controls");
       JMenu pointsMenu = new JMenu("points");
       JMenu layersMenu = new JMenu("Layers");

       //Set up the menu bar.
       menuBar.add(filesMenu);
       menuBar.add(controlsMenu);
       menuBar.add(pointsMenu);
       menuBar.add(layersMenu);
       return menuBar;
   }

//--------------------End Create
MenuBar------------------------------------------

//--------------------Create
ToolBar------------------------------------------

   public void createToolBar() {
       JButton button = null;

       //Create the toolbar.
       JToolBar toolBar = new JToolBar();
     toolBar.setFloatable(false);
     toolBar.setRollover(true);
       add(toolBar, BorderLayout.PAGE_START);
     addButtons(toolBar);
   }

       //Defines method to add the buttons to the toolBar
     protected void addButtons(JToolBar toolBar) {
       JButton button = null;

       //GPS File button
       button = makeNavigationButton("gpsfile", GPSFILE,
                                     "Choose GPS File",
                                     "GPS");
      button.setMnemonic('g');
       toolBar.add(button);

       //Create the text field used for GPS File location
       GPSTextField = new JFormattedTextField();
     GPSTextField.setColumns(50);
       GPSTextField.setEditable(true);
     toolBar.add(GPSTextField);

     //add separator
     toolBar.addSeparator();

       //Video File button
       button = makeNavigationButton("vidfile", VIDFILE,
                                     "Choose Video File",
                                     "VID");
      button.setMnemonic('v');
       toolBar.add(button);

        //Create the text field used for Video File location
       VidTextField = new JFormattedTextField();
     VidTextField.setColumns(50);
       VidTextField.setEditable(true);
     toolBar.add(VidTextField);

     //add separator
     toolBar.addSeparator();

       //Create GPV File button
       button = makeNavigationButton("gpvfile", GPVFILE,
                                     "Create GPV File",
                                     "GPV");
      button.setMnemonic('p');
       toolBar.add(button);

     //add separator
     toolBar.addSeparator();

      //Play button
       button = makeNavigationButton("pointer", PLAY,
                                     "Play GPV",
                                     "PLAY");
   button.setMnemonic('p');
   toolBar.add(button);

      //Stop button
       button = makeNavigationButton("stop", STOP,
                                     "Stop GPV",
                                     "STOP");
    button.setMnemonic('s');
      toolBar.add(button);

      //Pause button
       button = makeNavigationButton("pause", PAUSE,
                                     "Pause GPV",
                                     "PAUSE");
     button.setMnemonic('h');
       toolBar.add(button);

      //points button
       button = makeNavigationButton("newpoints", NEWPOINTS,
                                     "Choose New Start & Finish
Points",
                                     "POINTS");
     button.setMnemonic('n');
       toolBar.add(button);

      //Layers button
       button = makeNavigationButton("layers", LAYERS,
                                     "Show/Hide Layers",
                                     "LAYERS");
     button.setMnemonic('l');
       toolBar.add(button);

    }

   //Define method for making the navigation buttons
     protected JButton makeNavigationButton(String imageName,
                                          String actionCommand,
                                          String toolTipText,
                                          String altText) {
       //Look for the image.
       String imgLocation = "images/"
                            + imageName
                            + ".gif";
       URL imageURL = GPVLite.class.getResource(imgLocation);

       //Create and initialize the button.
       JButton button = new JButton();
       button.setActionCommand(actionCommand);
       button.setToolTipText(toolTipText);
       button.addActionListener(this);

       if (imageURL != null) {                      //image found
           button.setIcon(new ImageIcon(imageURL, altText));
       } else {                                     //no image found
           button.setText(altText);
           System.err.println("Resource not found: "
                              + imgLocation);
       }

       return button;
   }

     //Defines action method when GPS & Vid File buttons are pressed
     public void actionPerformed(ActionEvent e) {
     //File gpsFile = null;
       String cmd = e.getActionCommand();
       //int returnVal = fchooser.showOpenDialog(GPVLite.this);

       if (GPSFILE.equals(cmd)) { //GPS File button clicked
        int returnVal = fchooser.showOpenDialog(GPVLite.this);
         gpsFile = fchooser.getSelectedFile();
         GPSTextField.setValue(gpsFile);
         //GpvData gpvfile = new GpvData(gpsFile);
         //gpvfile.createGpvData();
       } else if (VIDFILE.equals(cmd)) { //Video File button clicked
        int returnVal = fchooser.showOpenDialog(GPVLite.this);
         File vidFile = fchooser.getSelectedFile();
         VidTextField.setValue(vidFile);
       } else if (GPVFILE.equals(cmd)) { //GPV File button clicked
         GpvData gpvdata = new GpvData(gpsFile);
         gpvdata.createGpvData();
     } else if (PLAY.equals(cmd)) { //Play button clicked
        //myDataViewer.latValue.setText("eat me");
        myDataViewer.updateData();
        myDataViewer.update();
     }

    }

//-----------------End Create
ToolBar------------------------------------------

   /**
    * Create the GUI and show it.  For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    */
   private static void createAndShowGUI() {
       //Set the look and feel to be that of the users operating
system.
       UIManager.getSystemLookAndFeelClassName();

       //Create and set up the window.
       JFrame frame = new JFrame("GPVLite");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

     //Set image icon for frame
     //java.net.URL imgURL =
GPVLite.class.getResource("images/GPI.jpg");
     //frame.setIconImage(new ImageIcon(imgURL).getImage());

       //Create/set menu bar and content pane.
       //GPVLite myGpvl = new GPVLite();
       frame.setJMenuBar(myGpvl.createMenuBar());
       myGpvl.createToolBar();
       myGpvl.setOpaque(true); //content panes must be opaque
       frame.setContentPane(myGpvl);

       //Display the window.
     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
     int screenX = screenSize.width;
     int screenY = screenSize.height - 50;
     frame.setSize(screenX, screenY);
       frame.setVisible(true);

   }

   public static void main(String[] args) {
       //Schedule a job for the event-dispatching thread:
       //creating and showing this application's GUI.
       javax.swing.SwingUtilities.invokeLater(new Runnable() {
           public void run() {
               createAndShowGUI();
           }
       });
   }
}

*********ClassB***********

/*
*
*/

import javax.swing.*;
import java.awt.*;
import javax.swing.JFormattedTextField;
import javax.swing.BorderFactory;
import javax.swing.border.EtchedBorder;
import javax.swing.border.Border;

public class DataViewer extends JPanel {

 JPanel blank, speedDisplay, avgDisplay, elevDisplay, distDisplay,
timeDisplay;
 JLabel speedLabel, speedValue, avgLabel, avgValue, elevLabel,
elevValue;
 JLabel distLabel, distValue, timeLabel, timeValue;
 JPanel latDisplay, lonDisplay, headDisplay, currentTitle,
summaryTitle, spacerPanel;
 JLabel latLabel, latValue, lonLabel, lonValue, headLabel, headValue,
currentLabel, summaryLabel;
 JPanel favgDisplay, maxelevDisplay, fdistDisplay, ftimeDisplay,
minelevDisplay,fmaxDisplay;
 JLabel favgLabel, favgValue, maxelevLabel, maxelevValue,
minelevLabel, minelevValue;
 JLabel ftimeLabel, ftimeValue, fdistLabel, fdistValue, fmaxLabel,
fmaxValue;

/*
* Constructors
*/

 //DataViewer Constructor with no parameters
    public DataViewer(){
     super(new GridBagLayout());
     makeGUI();
     //updateData();

    }

/*
* Methods
*/

 //Method to create the DataViewer GUI.
    public void makeGUI(){

    //Create Border variables
     Border loweredetched, raisedbevel;
     loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
     raisedbevel = BorderFactory.createRaisedBevelBorder();

       GridBagConstraints c = new GridBagConstraints();
     c.fill = GridBagConstraints.HORIZONTAL;

    //Create Panel for Current Data Title
     currentTitle = new JPanel();
     currentTitle.setLayout(new BorderLayout());
     currentLabel = new JLabel("Current Data",JLabel.CENTER);

    //Add label Current Data Panel
       currentTitle.add(currentLabel, BorderLayout.PAGE_END);
     currentTitle.setBorder(raisedbevel);

    //Add Panel for Current Data title to DataViewer
     c.gridwidth = 3;
       c.gridx = 0;
       c.gridy = 0;
       add(currentTitle, c);
     c.gridwidth = 1;

    //Create Panel for Avg Speed Display
     avgDisplay = new JPanel();
     avgDisplay.setLayout(new BorderLayout());
     avgLabel = new JLabel("Avg Speed",JLabel.CENTER);
     avgValue = new JLabel("0",JLabel.CENTER);
     avgValue.setFont(new Font("Arial", Font.BOLD, 20));
     avgValue.setForeground(Color.blue);

    //Add label and Value to Speed Display Panel
       avgDisplay.add(avgValue, BorderLayout.CENTER);
       avgDisplay.add(avgLabel, BorderLayout.PAGE_END);
     avgDisplay.setBorder(loweredetched);
     avgDisplay.setBackground(Color.white);

    //Add Panel for Avg Speed Display to DataViewer

       c.gridx = 0;
       c.gridy = 1;
       add(avgDisplay, c);

    //Create Panel for Elevation Display
     elevDisplay = new JPanel();
     elevDisplay.setLayout(new BorderLayout());
     elevLabel = new JLabel("Elevation",JLabel.CENTER);
     elevValue = new JLabel("0",JLabel.CENTER);
     elevValue.setFont(new Font("Arial", Font.BOLD, 20));
     elevValue.setForeground(Color.blue);

    //Add label and Value to Elevation Display Panel
       elevDisplay.add(elevValue, BorderLayout.CENTER);
       elevDisplay.add(elevLabel, BorderLayout.PAGE_END);
     elevDisplay.setBorder(loweredetched);
     elevDisplay.setBackground(Color.white);

    //Add Panel for Elevation Display to DataViewer

       c.gridx = 0;
       c.gridy = 2;
       add(elevDisplay, c);

    //Create Panel for Distance Display
     distDisplay = new JPanel();
     distDisplay.setLayout(new BorderLayout());
     distLabel = new JLabel("Distance",JLabel.CENTER);
     distValue = new JLabel("0",JLabel.CENTER);
     distValue.setFont(new Font("Arial", Font.BOLD, 20));
     distValue.setForeground(Color.blue);

    //Add label and Value to Distance Display Panel
       distDisplay.add(distValue, BorderLayout.CENTER);
       distDisplay.add(distLabel, BorderLayout.PAGE_END);
     distDisplay.setBorder(loweredetched);
     distDisplay.setBackground(Color.white);

    //Add Panel for Distance Display to DataViewer
     c.weightx = .33;
       c.gridx = 2;
       c.gridy = 1;
       add(distDisplay, c);

     //Create Panel for Time Display
     timeDisplay = new JPanel();
     timeDisplay.setLayout(new BorderLayout());
     timeLabel = new JLabel("Time",JLabel.CENTER);
     timeValue = new JLabel("0",JLabel.CENTER);
     timeValue.setFont(new Font("Arial", Font.BOLD, 20));
     timeValue.setForeground(Color.blue);

    //Add label and Value to Time Display Panel
       timeDisplay.add(timeValue, BorderLayout.CENTER);
       timeDisplay.add(timeLabel, BorderLayout.PAGE_END);
     timeDisplay.setBorder(loweredetched);
     timeDisplay.setBackground(Color.white);

    //Add Panel for Time Display to DataViewer
     
       c.gridx = 2;
       c.gridy = 2;
       add(timeDisplay, c);

    //Create Panel for Speed Display
     speedDisplay = new JPanel();
     speedDisplay.setLayout(new BorderLayout());
     speedLabel = new JLabel("Current Speed",JLabel.CENTER);
     speedValue = new JLabel("0",JLabel.CENTER);
     speedValue.setFont(new Font("Arial", Font.BOLD, 50));
     speedValue.setForeground(new Color(0xff0000));//Red

    //Add label and Value to Speed Display Panel
       speedDisplay.add(speedValue, BorderLayout.CENTER);
       speedDisplay.add(speedLabel, BorderLayout.PAGE_END);
     speedDisplay.setBorder(loweredetched);
     speedDisplay.setBackground(Color.white);

    //Add Panel for Speed Display to DataViewer
     
     c.ipady = 9;
     c.ipadx = 20;
       c.gridx = 1;
       c.gridy = 1;
     c.gridheight = 2;
       add(speedDisplay, c);
     c.gridheight = 1;

    //Create Panel for Latitude Display
     latDisplay = new JPanel();
     latDisplay.setLayout(new BorderLayout());
     latLabel = new JLabel("Latitude",JLabel.CENTER);
     latValue = new JLabel("0",JLabel.CENTER);
     latValue.setFont(new Font("Arial", Font.BOLD, 20));
     latValue.setForeground(Color.blue);

    //Add label and Value to lat Display Panel
       latDisplay.add(latValue, BorderLayout.CENTER);
       latDisplay.add(latLabel, BorderLayout.PAGE_END);
     latDisplay.setBorder(loweredetched);
     latDisplay.setBackground(Color.white);

    //Add Panel for Latitude Display to DataViewer
     c.ipady = 0;
     c.ipadx = 0;
       c.gridx = 0;
       c.gridy = 3;
       add(latDisplay, c);

     //Create Panel for Longitude Display
     lonDisplay = new JPanel();
     lonDisplay.setLayout(new BorderLayout());
     lonLabel = new JLabel("longitude",JLabel.CENTER);
     lonValue = new JLabel("0",JLabel.CENTER);
     lonValue.setFont(new Font("Arial", Font.BOLD, 20));
     lonValue.setForeground(Color.blue);

    //Add label and Value to Longitude Display Panel
       lonDisplay.add(lonValue, BorderLayout.CENTER);
       lonDisplay.add(lonLabel, BorderLayout.PAGE_END);
     lonDisplay.setBorder(loweredetched);
     lonDisplay.setBackground(Color.white);

    //Add Panel for Lonitude Display to DataViewer
     
       c.gridx = 1;
       c.gridy = 3;
       add(lonDisplay, c);

     //Create Panel for Heading Display
     headDisplay = new JPanel();
     headDisplay.setLayout(new BorderLayout());
     headLabel = new JLabel("Heading",JLabel.CENTER);
     headValue = new JLabel("0",JLabel.CENTER);
     headValue.setFont(new Font("Arial", Font.BOLD, 20));
     headValue.setForeground(Color.blue);

    //Add label and Value to Heading Display Panel
       headDisplay.add(headValue, BorderLayout.CENTER);
       headDisplay.add(headLabel, BorderLayout.PAGE_END);
     headDisplay.setBorder(loweredetched);
     headDisplay.setBackground(Color.white);

    //Add Panel for Heading Display to DataViewer
     c.weightx = .33;
       c.gridx = 2;
       c.gridy = 3;
       add(headDisplay, c);

    //Create Blank Spacer Panel
     spacerPanel = new JPanel();
     spacerPanel.setLayout(new BorderLayout());

    //Create Panel for Summary Data Title
     summaryTitle = new JPanel();
     summaryTitle.setLayout(new BorderLayout());
     summaryLabel = new JLabel("Summary Data",JLabel.CENTER);

    //Add label to Summary Data Panel
       summaryTitle.add(summaryLabel, BorderLayout.PAGE_END);
     summaryTitle.setBorder(raisedbevel);

    //Add Panel for Summary Data title to DataViewer
     //c.ipady = 40;
     c.gridwidth = 3;
       c.gridx = 0;
       c.gridy = 4;
       add(summaryTitle, c);
     c.gridwidth = 1;
     c.ipady = 0;

    //Create Panel for Final Avg Speed Display
     favgDisplay = new JPanel();
     favgDisplay.setLayout(new BorderLayout());
     favgLabel = new JLabel("Avg Speed",JLabel.CENTER);
     favgValue = new JLabel("0",JLabel.CENTER);
     favgValue.setFont(new Font("Arial", Font.BOLD, 20));
     //favgValue.setForeground(Color.blue);

    //Add label and Value to Final Avg Speed Display Panel
       favgDisplay.add(favgValue, BorderLayout.CENTER);
       favgDisplay.add(favgLabel, BorderLayout.PAGE_END);
     favgDisplay.setBorder(loweredetched);
     favgDisplay.setBackground(Color.white);

    //Add Panel for Final Avg Speed Display to DataViewer
       c.gridx = 0;
       c.gridy = 5;
       add(favgDisplay, c);

    //Create Panel for Final Max Speed Display
     fmaxDisplay = new JPanel();
     fmaxDisplay.setLayout(new BorderLayout());
     fmaxLabel = new JLabel("Max Speed",JLabel.CENTER);
     fmaxValue = new JLabel("0",JLabel.CENTER);
     fmaxValue.setFont(new Font("Arial", Font.BOLD, 20));
     //fmaxValue.setForeground(Color.blue);

    //Add label and Value to Final max Speed Display Panel
       fmaxDisplay.add(fmaxValue, BorderLayout.CENTER);
       fmaxDisplay.add(fmaxLabel, BorderLayout.PAGE_END);
     fmaxDisplay.setBorder(loweredetched);
     fmaxDisplay.setBackground(Color.white);

    //Add Panel for Final max Speed Display to DataViewer
       c.gridx = 1;
       c.gridy = 5;
       add(fmaxDisplay, c);

    //Create Panel for Final Distance Display
     fdistDisplay = new JPanel();
     fdistDisplay.setLayout(new BorderLayout());
     fdistLabel = new JLabel("Distance",JLabel.CENTER);
     fdistValue = new JLabel("0",JLabel.CENTER);
     fdistValue.setFont(new Font("Arial", Font.BOLD, 20));
     //fdistValue.setForeground(Color.blue);

    //Add label and Value to Final Distance Display Panel
       fdistDisplay.add(fdistValue, BorderLayout.CENTER);
       fdistDisplay.add(fdistLabel, BorderLayout.PAGE_END);
     fdistDisplay.setBorder(loweredetched);
     fdistDisplay.setBackground(Color.white);

    //Add Panel for Distance Display to DataViewer
     c.weightx = .33;
       c.gridx = 2;
       c.gridy = 5;
       add(fdistDisplay, c);

     //Create Panel for Final Time Display
     ftimeDisplay = new JPanel();
     ftimeDisplay.setLayout(new BorderLayout());
     ftimeLabel = new JLabel("Time",JLabel.CENTER);
     ftimeValue = new JLabel("0",JLabel.CENTER);
     ftimeValue.setFont(new Font("Arial", Font.BOLD, 20));
     //ftimeValue.setForeground(Color.blue);

    //Add label and Value to Final Time Display Panel
       ftimeDisplay.add(ftimeValue, BorderLayout.CENTER);
       ftimeDisplay.add(ftimeLabel, BorderLayout.PAGE_END);
     ftimeDisplay.setBorder(loweredetched);
     ftimeDisplay.setBackground(Color.white);

    //Add Panel for Time Display to DataViewer
     
       c.gridx = 2;
       c.gridy = 6;
       add(ftimeDisplay, c);

    //Create Panel for Max Elevation Display
     maxelevDisplay = new JPanel();
     maxelevDisplay.setLayout(new BorderLayout());
     maxelevLabel = new JLabel("Max Elev",JLabel.CENTER);
     maxelevValue = new JLabel("0",JLabel.CENTER);
     maxelevValue.setFont(new Font("Arial", Font.BOLD, 20));
     //maxelevValue.setForeground(Color.blue);

    //Add label and Value to Max Elevation Display Panel
       maxelevDisplay.add(maxelevValue, BorderLayout.CENTER);
       maxelevDisplay.add(maxelevLabel, BorderLayout.PAGE_END);
     maxelevDisplay.setBorder(loweredetched);
     maxelevDisplay.setBackground(Color.white);

    //Add Panel for Max Elevation Display to DataViewer

       c.gridx = 1;
       c.gridy = 6;
       add(maxelevDisplay, c);

    //Create Panel for min Elevation Display
     minelevDisplay = new JPanel();
     minelevDisplay.setLayout(new BorderLayout());
     minelevLabel = new JLabel("Min Elev",JLabel.CENTER);
     minelevValue = new JLabel("0",JLabel.CENTER);
     minelevValue.setFont(new Font("Arial", Font.BOLD, 20));
     //minelevValue.setForeground(Color.blue);

    //Add label and Value to min Elevation Display Panel
       minelevDisplay.add(minelevValue, BorderLayout.CENTER);
       minelevDisplay.add(minelevLabel, BorderLayout.PAGE_END);
     minelevDisplay.setBorder(loweredetched);
     minelevDisplay.setBackground(Color.white);

    //Add Panel for min Elevation Display to DataViewer

       c.gridx = 0;
       c.gridy = 6;
       add(minelevDisplay, c);
    }
 /*Method to update data
    public void updateData() {
     latValue.setText("Help me");
    }
Andrew Thompson - 18 Jun 2004 08:32 GMT
>>> Try posting your complete code...
>>
>> For tips..
>> <http://www.physci.org/codes/sscce.jsp>
>
> Here's my code.

Rather *long* though.. Note the meaning of
the first letter of SSCCE..

It should take about 40 lines to demonstrate
two classes not communicating via a Label.

(And no, I do not have time to look at the
code from your 718 line post!)

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

hoyttech2004@yahoo.com - 18 Jun 2004 21:04 GMT
> >>> Try posting your complete code...
> >>
[quoted text clipped - 11 lines]
> (And no, I do not have time to look at the
> code from your 718 line post!)

Sorry about that. Won't happen again.

I stripped my ClassA down to nothing but a button and my ClassB inside
a JFrame. The Jlabel updates OK now. I guess I'll try stripping out
some components one by one and see if I can locate the culprit.

Thanks.
Roedy Green - 18 Jun 2004 21:15 GMT
On 18 Jun 2004 13:04:51 -0700, hoyttech2004@yahoo.com wrote or quoted

>I stripped my ClassA down to nothing but a button and my ClassB inside
>a JFrame. The Jlabel updates OK now. I guess I'll try stripping out
>some components one by one and see if I can locate the culprit.

That often is caused by accidentally shadowing a variable.  

Look for duplicate definitions of the crucial variables.  Compile with
Jikes to get automatic warnings.

see http://mindprod.com/jgloss/jikes.html

Signature

Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Andrew Thompson - 19 Jun 2004 00:11 GMT
> Andrew Thompson <SeeMySites@www.invalid> wrote in message ...
..
>>> Here's my code.
>>
>> Rather *long* though..
..
> Sorry about that. Won't happen again.

It's cool.

> I stripped my ClassA down to nothing but a button and my ClassB inside
> a JFrame. The Jlabel updates OK now. I guess I'll try stripping out
> some components one by one and see if I can locate the culprit.

Yay!  I think you are getting the
'inner meaning' of the SSCCE.    ;-)

Let us know how you go.

Signature

Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Will - 18 Jun 2004 18:10 GMT
Try this...

public void updateData() {
   latValue.setText("Help me");
   repaint();
}

> Hi,
>
[quoted text clipped - 26 lines]
>
> Thanks in advance for your help.
hoyttech2004@yahoo.com - 19 Jun 2004 01:37 GMT
> Try this...
>
> public void updateData() {
>     latValue.setText("Help me");
>     repaint();
> }

Yes, I've tried repaint. I thought it didn't work but I just realized

it almost works now. I have to double-click or click the button twice.
I only have to single-click my other buttons. Any ideas?

> > Hi,
> >
[quoted text clipped - 26 lines]
> >
> > Thanks in advance for your help.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.