jlabel.setText, event from another class does not

can someone help me this code?
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import java.awt.event.*;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class Frame1 extends JFrame{
    private JFrame m2;
    private JButton btn;
    private JTabbedPane tab;
    public Frame1(){
        setTitle("Frame1");
        setLayout(new java.awt.BorderLayout());
  
        tab = new JTabbedPane();
        tab.addTab("Tab1",new JLabel("Tab1"));
        tab.addTab("Tab2",new JLabel("Tab2"));
        tab.addTab("Tab3",new JLabel("Tab3"));
        add(tab,BorderLayout.CENTER);
        tab.addChangeListener(new ChangeListener(){
                public void stateChanged(ChangeEvent evt){
                    int currtab = tab.getSelectedIndex();
                    System.out.println("Frame1: "+currtab); //<- it works
                   new myPanel(currtab); 
                    //new myPanel(new JLabel(),currtab);
                }
        });
        
        m2 = new Frame2(); 
        m2.setBounds(300,20,400,300);
        
     btn = new JButton("Show Frame2");
     add(btn,BorderLayout.SOUTH);
      btn.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
       m2.setVisible(true);
      }
      }
     ); 
       
      setVisible(true);
      setBounds(250,10,500,400);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
    }
    public static void main(String[]args){
        new Frame1();
    }
}
------------------------------------------------------------------------------------------------------------
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Frame2 extends JFrame{
    private JPanel pan;
    public Frame2(){
        setAlwaysOnTop(true);
        setLayout(new java.awt.BorderLayout());
        pan = new myPanel();
        add(pan,BorderLayout.CENTER); 
    }
}
---------------------------------------------------------------------------------------------------
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class myPanel extends JPanel{
    private JLabel label = new JLabel("Test jLabel changed");
  //private JLabel label;  //<- not working
    /*
     * this constructor still not working
    public myPanel(JLabel l,int i){
        label = l;
        System.out.println("myPanel: "+i);
        //label = new JLabel(""+i); //<- not working
        label.setText(String.valueOf(i)); //<- not working
    }
     */
   public myPanel(int i){
        System.out.println("myPanel: "+i);
        //label = new JLabel(""+i); //<- not working
        label.setText(String.valueOf(i)); //<- not working
    }
        
    public myPanel(){
       setBackground(Color.ORANGE);
       setLayout(new java.awt.BorderLayout());
       add(label,BorderLayout.NORTH);
    }
}
Im trying to update the label text using myPanel.java label.setText using stateChanged tabPane in Frame1.java

Published by: jhovarie on August 18, 2011 21:56

Published by: jhovarie on August 19, 2011 06:50

Published by: jhovarie on August 19, 2011 23:19

"First of all, use the formatting code"
I don't know where he is.

Already answered - in a much more civil way I wish!

and also I already explain what im trying to do maybe didn't it read the comments in my code and the bellows of my last code message. I have already explained my problem.

I did not read your comments either, because the code was not formatted (hard to read =). And because nothing in the text of the proposed non-code that there comments in code that has highlighted the problem.

Im trying to update the label text using myPanel.java label.setText using stateChanged tabPane in Frame1.java
look at my code earlier there is a code like that (...)

The code you cite here is irrelevant. The problem is in the event listener:

public void stateChanged(ChangeEvent evt){
  int currtab = tab.getSelectedIndex();
  System.out.println("Frame1: "+currtab); //<- it works
  new myPanel(currtab);
  //new myPanel(new JLabel(),currtab);
}

So whenever you change your tab, you create an instance of myPanel, that is strange in itself; but worse yet, what are you doing with the newly created group? You don't add it anywhere. What then is this instance?
The code proposes label.setText (...) is in the constructor of mypanel, but it changes the text of the new label in the new Panel, not existing the existing label in the Panel text.

Tags: Java

Similar Questions

  • kb2596615 causes ade to failure, error was 459: object or class does not support the set of events

    A couple of my users started getting our application error messages ade grown after you apply this update. Everything is well after its withdrawal. First mistake was 459: object or class does not support the set of events. Basically, no event has worked. Why is this update break my application? It should be removed from the queue of the update.

    Okay, I've worked on it with Microsoft, and the actual cause turns out to be:

    MS12-060 security update affects the functionality of Access database
    http://support.Microsoft.com/kb/2748410

    This article updated fingers MS12-060, specifically KB 2687441, as the culprit.

    It turned out that ActiveX controls on the form (specifically the Microsoft Common Controls 6.0 Toolbar), caused the failure.

    The solution was simple: on a patched machine, open each form with an ActiveX control in design mode, compile and save it. It worked for me. Ignore the details of the solution that I wrote in the previous post!

    You may need to resave MSCOMCTL. OCX, as suggested in the article, to get your databases to work.

    -Ken

  • When you try to import the bookmarks, the ability to import data from another browser is not active in the import and backup from the tap in the history. So, how to import bookmarks on my file?

    I followed the instructions of Firefox to import bookmarks/favorites to Internet Explorer. It does not work because the import data from another browser is not active in the import tab and backup in the history. The instructions read to use this tab, but does not work because it cannot be selected.

    Make sure that you are not Firefox running in permanent private browsing mode.

    To view the history settings and cookies, choose: Tools > Options > privacy, choose the setting Firefox will: use the custom settings for the story of

    • Uncheck the box: [] "always use the navigation mode private.
  • Windows 7 Defrag from command line does not work

    We are running Windows 7 in a virtualized environment. When you run windows defrag hourly use of the command line, it does not work. The order that I will execute as administrator is

    C:\Windows\System32>defrag/c

    Microsoft Disk Defragmenter
    Copyright (c) 2007 Microsoft Corp.

    It displays the above message and leaves back to the command prompt. However if I run the defrag C: command it does not. Defragmentation from the GUI works so as long as both drives (C: and system reserved) are selected and when I click on defragment drives, works very well.

    I am concerned about defrag from the Task Scheduler with the command ' defrag/c' (self programmed to help set up the calendar... from Disk Defragmenter) does not work and the system never gets defragmented automatically.

    This only happens with some of the windows virtual machine 7 we have.

    There are no entries in the event log that point to defragmentation (using the Task Scheduler). Anything can happen on the ideas?

    Hello Sebastian,.

    Thanks for posting your question on the Forum of the Microsoft community.

    The question will be better suited to the audience of it professionals on the TechNet forums.

    I would recommend posting your query in the TechNet Forums.
     
    TechNet Forum
    http://social.technet.Microsoft.com/forums/en-us/home?category=w7itpro

    Thank you

  • "Show my windows and tabs from last time ' does not work in version 3.6.8

    I select "show my windows and tabs from last time ' on the Options window - Panel general"when firefox starts", but it opens as my home page every time I start firefox.

    I tried this on two different computers. Both of them have the same problem.

    It worked fine in previous versions, but it does not work in version 3.6.8.

    If you use delete, search and download Firefox browsing history in Firefox 3.5 and later versions to clear the 'browsing history' the closing of Firefox then in restaurant tabs in the last session ("Save and exit" or "show my windows and tabs from last time ') does not work.

  • "For more specific class" does not not on sbRIO 9636

    The application that I am forcing me to programmatically access arbitrary components of a nested group. Currently, I am doing the browsing the cluster using his property [] node recursively controls. Currently, my accessor VI to accomplish this works very well on a normal PC but does not work on my target in real time, a sbRIO 9636.

    After some research, I determined that the function "To more specific class" does not work on my target in real time. I have attached a code base that shows the heart of the problem. It works fine on a PC but will return an error 53 when running on my target in real time.

    A few questions:

    (1) is 'To more specific class' supported on the sbRIO 9636 or not?
    (2) if it is supported, what am I doing wrong?

    (3) if it is not taken in charge, what are other methods for access by the arbitrary elements of a nested cluster program?
    (4) if it is not supported, why LabVIEW allows me to place the feature even when the sbRIO 9636 is explicitly selected as my goal in my LabVIEW project? It seems prudent to restrict its use, if it is not supported. My day job has been effectively wasted because of this problem.

    For reference, here's a few previous discussions

    http://forums.NI.com/T5/real-time-measurement-and/modifing-cluster-component-properties-on-sbRIO-No-...

    http://forums.NI.com/T5/real-time-measurement-and/quot-Manager-call-not-supported-quot-when-typecast...

    Thank you
    JAnthony

    The other posts are correct, because it is currently not possible to use the function on a real-time target. This is a known issue and is being investigated for correction, but currently there is no work around. It is available on the pallets that this behavior is not intentional and should work.

    You have described your application requires that recursively through a table and access to specific data. Does this mean that the Data Structure might be different when the vi is run and you need to adapt to a changing data type? If this isn't the case, then all you need to do is to get the value of the reference and then ungroup the cluster as needed then store the changed values to the same reference.

    If you're going to have to settle you will encounter difficulties to be determined pragmatically you should do but I have a suggestion. Create a cluster with an enum and a Variant. You can use the enumeration to set the type of the variant in question. He chooses the type to convert the variant according to the code. It is a similar structure, like messages in queue manager and his messages that happening except that you will be passing a reference to this group that has both the message and the payload in one. The reference could be used to get the value and then the code must only be written to accept the Cluster of Enum and variant you can then convert the variant to the appropriate type for later use. For best performance, you also use in Place of the Structure element.

    It's only a means potentially accomplish what you want. If you describe your program and needs more in depth, we are able to offer a more suitable solution for your application that does what you need. I wish you a nice day!

  • My activation key for windows 7 (bought from my college) does not work. How can I contact someone who can help?

    My activation key for windows 7 (bought from my college) does not work.  How can I contact someone who can help?

    -Mike

    Hello djplexus

    First, you will need to understand how to set up the dual boot. This will allow you to be able to choose between XP and 7 at startup.
    With regard to the creation of an image of Windows XP Backup there is no Windows XP software that will do it for you. You will need to look to third-party vendors for support with this issue. Thank you.
  • a pc that is sharing the printer and another pc does not accept the same network printer on xp pro sp3

    a pc that is sharing the printer and another pc does not accept the same network printer on xp pro sp3
    What is the solution?

    Check out these links

    http://TechNet.Microsoft.com/en-us/library/bb457001.aspx

    http://UIs.Georgetown.edu/software/documentation/WinXP/WinXP.network.printer.html

  • Error 1717 event log stopped and does not restart

    Dear friends,

    I thought that I had a problem with Google Music. He stops and give me an error code so I tried to uninstall to reinstall. He hung up to uninstall (I have a screen shot) and gave me the following code.
    "Error code 1717 in DllMain.
    This happens usually when the recorder of events from Windows service is not running. Setup will continue without log status messages.
    Now when Google Music tries to start at startup and at regular intervals, I get the same error Code 1717. I can't uninstall and it will not work.
    Just a day or two before this happened I had problems with the Weather Channel desktop Google gadgets and tried to uninstall that and he doesn't uninstall properly and still won't. I guess it could be where it all started, but don't tell me anything. Maybe he could tell you something of value if you can help me.
    I found a few posts here and there online that suggested:
    1. from the 'Windows event log"manually in Safe Mode, but that has not worked.
    2 remove or change the name of the RtBackup folder in the C:\Windows\System32\LogFiles\WMI folder. I tried to do this as "Administrator", but it would not allow me to change the name of the folder or to remove the folder. I have studied also change permissions for the folder, but I have all the permissions as the administrator. It simply cannot afford to make this change.
    The system is a Dell Studio 540 (64-bit) running Windows Vista Home Premium SP2. Updates are current as of yesterday. I just checked and I have 2 new Vista install now.
    Any suggestions? Any help would be greatly appreciated.
    Tony

    Hi Tony,.

    You can check out the following link and check if it helps to solve the problem:

    Failed to start service on Windows 7 windows event log. Error 4201.

    Important note: this response contains a reference to the third party World Wide Web site.

    Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

  • update from Sony site does not recognize my OS.

    I run windows vista edition Home premium on my vaio. update from Sony site does not reconoize my BONES. help Sony tech was unable to solve the problem after 15 contacts over a period of 2 years. I was not able to get the vaio updates since the question has been raised.

    I'm sorry, but your problem seems to be with Sony.

    Sony is responsible for all their updates for Vista operating system support, they delivered, not Microsoft.

    See you soon. Mick Murphy - Microsoft partner

  • Windows Explorer "option remove from this list" DOES NOT always WORK

    In Windows 7:
    When you right-click the Windows Explorer button at the bottom of the screen on the task bar, it has an option to "remove from this list. all Frequent ' point/place' that there are listed...

    I used this option during most of the items listed to clean a little bit because I don't want to see it all.

    BUT:
    I have now six items/places to the left.  I want three of them to stay.  I would like to 'Remove' the other three, but the option "Remove from this list" DOES NOT WORK!

    I tried:
    -Manually remove items/locations...   Always in the list.  So I put them back
    -Search for places objects in a windows search to see if they appeared in a file list somewhere that I could remove a manually.  No foumd.

    HOW to REMOVE THESE UNWANTED ITEMS/LOCATIONS in the list of Windows Explorer?

    Thank you.   -TomE

    NOTE: A second problem is that I couldn't use a sign less "-" to exclude elements of my research, when I used Windows Search.  I tried to use '-internet "to exclude references to Internet Explorer.  It did not work.  There for me in the past.

    Hello

    Right-click the Start button, and then select Properties.

    In the privacy section, remove the check mark from the option "store and displayrecently open items in the Start Menu and the taskbar" . CLIck apply/OK.

    Check the list of shortcuts in Windows Explorer and recent items section should be empty.

    Go back and re - activate this option.

    NOTE: this procedure will empty all the list Jump list recent items as well as the recent items on the Start Menu.

    I hope this helps.

    Thank you for using Windows 7 Ronnie Vernon MVP

  • create a pdf from a scanner does not black and white?

    create a pdf from a scanner does not black and white? Acrobat 9 pro only allows a customized analysis?

    Hi mikes84641121935 ,

    Acrobat 9 is not compatible with Windows 10. It may or may not work.

    Please refer to this article: Adobe Acrobat required configuration

    You can launch the scanner interface by going to the start menu or the control panel.  When you first connect your printer/scanner to your computer via USB or wireless, the scanner driver to install and can scan from its native interface. You can find it in all programs in the Windows Start menu.

    By ex. If you have HP Scanner, click Start and type hp scan. Also, you can go to control panel and can run the scan from there function. Hold down the Windows key and then press R on your keyboard, type of control in the run, find dialog box, and click on devices and printers > select your scanner and right-click on it. Try scanning from there and let us know if you are able to do.

    In addition, you can try to repair Acrobat installation, launch Acrobat and go to the Help menu > and click on repair Installation, after repair, restart Acrobat and check if you are able to scan.

  • I bought Adobe Acrobat DC. We use it in a desktop environment. Is there a way to "TURN OFF" the concept of cloud for another user does not see a confidential pdf in their queue?

    Is there a way to "TURN OFF" the concept of cloud for another user does not see a confidential pdf in their queue?

    I tried to contact technical support to the 800-833-6687 but was put through several automatic guests and disconnected.

    Hi plumasca,

    Refer to this topic for help disable features/services online in Acrobat/Reader DC?

    Kind regards
    Nicos

  • My acrobat from adobe pro does not work and no earlier version is available download again with my n serial

    My acrobat from adobe pro does not work and no earlier version is available download again with my serial number

    He can count on what version you need to download... Here are the links for the perpetually licensed versions that Adobe has:

    Acrobat XI, X - http://helpx.adobe.com/acrobat/kb/acrobat-downloads.html

    Acrobat 9: 8 - http://helpx.adobe.com/acrobat/kb/acrobat-8-9-product-downloads.html

  • Calling functions from another class

    How one accesses a function from another class?

    Let's say I have a file called .as hand. My flash file uses this as this is the main class to make it work when you test the program. Let's say I have another class named Test that looks like this:

    package

    {

    public class Test

    {

    public void Test()

    {

    trace ("why don't you work?');

    }

    }

    }

    I want call the Test function when the game takes place (in the appellant to hand), how would he enter the main run file? I imported to it, made sure that the functions were public/static, created as a variable and it still doesn't work.

    Any help would be good

    the constructor for a class is different from a 'normal' function

    If you can't do something like

    meow: Test of var = new Meow();

    To call it thus:

    test: Test of var = new Test();

    test. Meow();

Maybe you are looking for

  • Satellite Pro L770 restarts - multiple irp complete application error

    Hello I have a strange problem, I am running Windows 7 and, occasionally, when I sign out and close my laptop it seems to restart itself and displays a blue screen with "mutiple_irp_completerequests" on this subject.Then I pressed the on / off to mak

  • Satellite L640 hangs at the splash screen

    Hi all I have a L640 / 01 H that I bought earlier this year. In addition to the original Windows 7 OS, I installed a Linux system on a separate partition. Earlier today, I was using Linux (which is what I normally use) and everything was really slow.

  • HP dv6 envy: wipe HARD drive

    My laptop could not start. He kept saying 'Please Wait'. I took the HARD drive and made a slave on another computer; took all the user files and then formatted the HARD drive. When I reconnected the HARD drive in its own machine, the computer says th

  • Problem with Vista SP2 upgrade

    After upgrade my vista SP1 to SP2, it takes a long time for the display of connection to appear. I had seen n number of related topics, and yet am not able to solve the problem... Please help me... !!!

  • hard drive does not recognize memory stick or inserted disks

    nothing happens with the computer when we put a disk or the memory of my meter stick in the hard drive