Repainting a JFrame when a JPANEL is changed

Hi,
I have a jframe with one panel.
Inside the jframe there are also two jbuttons.
Inside the frame I have a List<Panel> panelList which displays one panel at a time in the frame.
When the up jbutton is selected I want the frame to display the next panel in the panelList.
Currently I construct a new frame and dispose of the old one.
Can I just replace the old panel and repaint the frame?
Cheers
Bobby

Use a CardLayout.

Similar Messages

  • JFrame: How to detect a change in size?

    Hello everyone,
    I have a question related to the size of a JFrame or JPanel. I add a few JPanels to a JFrame and I wanted to detect when the size of the JFrame window or the JPanel itself had changed (if the user pressed the "Maximize icon" or simply dragged the window size from the one of the corner of the window). I am not sure if I need a listener added to the Frame, and what kind of listener that would be (if any exists, I am not sure).
    I have another question regarding the class Dimension. I add JPanel's to my JFrame and I use the class Dimension to get the size of the panel with the getSize() method. I wanted to know when is the sooner that I could call this method to get the right size. For example, I use it in a few methods like the paintComponent, the mouseReleased and mouseDragged method, but I wished to get the correct size as soon as possible and only compute it once (or update it if the JPanel sized change). I am wondering why the size is 0 while I call this method inside the constructor and if there is any method where I can call it before actually doing anything to the JFrame please.
    I hope my questions are somewhat clear.
    Thanks for all your help, it is very much appreciated.

    I am having one more issue.
    I have implemented the ComponentListener for each of my JPanel and used the componentResized and componentShown to calculate the size of my panel.
    This works great when I resize the JFrame using one of the corners, but not when the "maximize button" (in the title bar next to the corss) is pressed.
    Is there any way please to fix this? Thank you.

  • JPanel content change with MouseClicked

    Here is my very simple question.
    I create a JFrame, and a JPanel in it, and create a content via toAdd class which implements MouseListener.
    What can I do to refresh the content of JPanel when MouseClicked?
    I tried many things but since they did not work, may be for now, I should only ask, here is the code:
    package jpanel;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class App1 {
        private static class toAdd extends JPanel implements MouseListener{
            public void paint(Graphics g){
                super.paintComponent(g);
                g.drawString("deneme", 20, 50);
            public void mousePressed(MouseEvent evt){}
            public void mouseReleased(MouseEvent evt){}
            public void mouseClicked(MouseEvent evt){
            // my question is related to this part.
            public void mouseEntered(MouseEvent evt){}
            public void mouseExited(MouseEvent evt){}
        public static void main(String[] args){
            toAdd toAdd = new toAdd();
            JPanel content = new JPanel();
            content.setLayout(new BorderLayout());
            content.add(toAdd, BorderLayout.CENTER);
            JFrame window = new JFrame("Platform");
            window.setContentPane(content);
            window.setSize(100, 200);
            window.setLocation(100, 100);
            window.setVisible(true);
    }Message was edited by:
    tolgafiratoglu

    Like this perhaps?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class App1 {
        private static class toAdd extends JPanel implements MouseListener{
            public toAdd() {
                addMouseListener(this);
            private int wordindex = 0;
            private String[] words = { "not clicked", "clicked" };
            public void paint(Graphics g){
                super.paintComponent(g);
                g.drawString(words[wordindex], 20, 50);
            public void mousePressed(MouseEvent evt){}
            public void mouseReleased(MouseEvent evt){}
            public void mouseClicked(MouseEvent evt){
                wordindex = wordindex == 0 ? 1 : 0;
                invalidate();
                repaint();
            public void mouseEntered(MouseEvent evt){}
            public void mouseExited(MouseEvent evt){}
        public static void main(String[] args){
            toAdd toAdd = new toAdd();       
            JPanel content = new JPanel();
            content.setLayout(new BorderLayout());
            content.add(toAdd, BorderLayout.CENTER);
            JFrame window = new JFrame("Platform");
            window.setContentPane(content);
            window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            window.pack();
            window.setSize(100, 200);
            window.setLocation(100, 100);
            window.setVisible(true);
    }Message was edited by:
    deeprave

  • JFrame switching to JPanel

    My JFrame is working perfectly. Its got a button on it that when pressed I want my panel to appear. I don't mind if the other one dissapears or stays there.
    I have created a JPanel in a seperate java file. Its fine aswell, but now I want it to appear when I hit my add button.
    I expecetd it to be a case of a new instance the following would work;
    JPanelAdd panel = new JPanelAdd();But no joy. Then I thought I could do something like panel.show();
    So, I'm obviously doing something basic wrong. I'd appreciate the help.

    No joy with the following:
    private void
    jButtonAddMouseClicked(java.awt.event.MouseEvent evt)
    JPanelAdd panel = new JPanelAdd();
    this.getContentPane().add(panel);
    panel.setVisible(true);
    System.out.println("got here");
    Being a novice myself, I can only tell you that these two code snippets:
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
            dlgPrueba.setVisible(true);
        private void miFilePreferencesLoadActionPerformed(java.awt.event.ActionEvent evt) {                                                     
            PrefDialog pf = new PrefDialog();
            System.out.println("Option 'Load Preferences...' has been choosed.");
            pf.setVisible(true);
        }                                                     work for me. The first one launches a jDialog created inside the jFrame (when I say "inside", I mean that you add a jDialog from the Palette Manager while editing the jFrame; that jDialog is bound to be used exclusively as part of the jFrame).
    The second one is closest to your environment. I've got a separate .java file to define the class "PrefDialog" which, as you may suppose, extends jDialog.
    In both cases, the dialogs work fine. As a side note, the first runs on a button click, while the second one gets launched by choosing a menu item.
    Sorry to not be able to help you further.

  • My Excel with PowerPivots acts weird, it hangs when i try to change font color

    Hi 
    I am facing a weird issue using PowerPivot in my workbook, there is a worksheet named Charts in my workbook and all the charts i am using resides in that worksheet. Whenever i try to change the font color in that sheet, my excel's color palette goes blur
    and then everything just freezes and turns black. This problem is happening only with Charts worksheet, when i try to change the color in other sheets, it works just, the problem is only with Charts sheet. File
    size is 16 MB, there are just 10 pivot tables with some calculations and some calculated fields. There are no add-ins other than PowerPivot. 
    Thanks,
    Shanker

    Hi,
    In regarding of the issue, please provide us more information to assist you better.
    Do you receive any error message?
    Which Excel version are you using?  Excel 2013 or other?
    Which workbook format are you using? XLS or XLSX?
    Are you performing any specific task?
    According to your description, this issue seems only occur with the special worksheet "Charts".
    Firstly, I recommend we copy all of the content to a new/blank Excel file to test.
    If it works fine, this issue might be caused by the "Charts" workbook itself. We'd better check the "Charts" workbook. Or re-build the file with a new workbook.
    If it still makes Excel hang with a new file, this issue might due to the content. Please check the content first.
    Secondly, we could follow below KB to troubleshoot this issue:
    https://support2.microsoft.com/kb/2758592/en-us?wa=wsignin1.0
    Thirdly, if the issue still exists, we may try to collect the Event log and App crash dump file to do advanced troubleshooting.
    Event log:
    http://windows.microsoft.com/en-US/windows7/Open-Event-Viewer
    App crash dump file:
    First enable app crash dump collection by copying following words into notepad, saving it as dump.reg and importing
    it:
    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\localdumps\EXCEL.EXE]
    "DumpFolder"=hex(2):63,00,3a,00,5c,00,63,00,72,00,61,00,73,00,68,00,64,00,75,\
      00,6d,00,70,00,73,00,00,00
    "DumpCount"=dword:00000010
    "DumpType"=dword:00000001
    "CustomDumpFlags"=dword:00000000
    Then, open Excel
    to repro the issue. If crash issue appeared, please find the crashdump file under c:\.
    To further help you, please upload this file into Skydrive and shared the link here.
    Also, you can try to analyze dump by yourself if you would like to:
    How to analyze app crash dump file:
    http://blogs.technet.com/b/askperf/archive/2007/05/29/basic-debugging-of-an-application-crash.aspx
    Hope it's helpful.
    Regards,
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • My apple ID and password, recognized through out the Cloud, is not being recognized in the itunes store. I am signed into itunes.When I want to change something in my account, the sign in prompt comes up and doesn't recognize my PW

    My apple ID and password, recognized through out the Cloud, is not being recognized in the itunes store. I am signed into itunes.When I want to change something in my account, the sign in prompt comes up and doesn't recognize my PW

    Solved the problem. I had to allow cookies for safari and it run - as here: Re: itunes keeps asking for my apple id password. it's NOT entered incorrectly.

  • TS2446 itunes will not take my security answers, and when i try to change them it asks me again and it still wont take it, i cant make any purchases. HELP!

    I dont know what to do it wont take my security answers when i answer them correctly, and when i try to change them it askes me for them again and still wont take them, and the worst part is i cant make any purchases. Please help its been going on forever. Btw i just got a new laptop and i synced my iphone with it, and for the First Purchase i have to answer the secutiry questions. See my problem?

          Congratulations on being the next victim of Apple's current SNAFU!      
    If you don't have a rescue email address set, then you're SoL.
    If you do, then reset your info and check in there.
    If not, you'll have to contact iTS, and wait for God knows how long for Apple to complete its pending investigation in this SNAFU.
    iTunes Store Support
    http://www.apple.com/emea/support/itunes/contact.html

  • Text deleting when I try to change color or actual font

    I will try to explain. So say I have a photo (or blank canvas) and I have typed words on it. If later I go and double click the word (or layer, etc) so that I can change the color of the word(s) &/or change the actual font, it will just automatically delete the whole word(s) on that layer.... which means I have to go change the color &/or font again BEFORE typing anything, and then re-type it all. So I guess in other words... I guess the text is deleting when I try to change the color or actual font (after it's already typed). Sorry if that's confusing.
    (I have a Mac, and I am using the Photoshop that comes with the Creative Cloud subscription).

    Something is wrong here, the text should not delete when changing font, color or whatever.
    But try this. First off you don't need to double click to change the text atributes.
    Just make sure you are on the correct text layer, have commited the text but keep the text tool the active tool. Now in the options bar you can change any or all attributes (color, size, font etc). The text updates real time.
    You only need to select word(s) if you want that word to be in another color/font/whatever than the other words of that same text layer.
    If you want to change the attributes of more than one text layer in one go then you must select those layers before changing attributes in the options bar.

  • I am using a work laptop and have the same problem. When I try to change the "configure proxy", they only available option is "use this proxy server for all protocols". Could it be that my system administrator blocked me from changing it since they don'

    I am using a work laptop and have the same problem. When I try to change the "configure proxy", they only available option is "use this proxy server for all protocols". Could it be that my system administrator blocked me from changing it since they don't want us to use Firefox.
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.4; FNGP_SYS)

    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]
    If it does work in Safe-mode then disable all your extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    You can use "Disable all add-ons" on the ''Safe mode'' start window.
    You have to close and restart Firefox after each change via "File > Exit" (on Mac: "Firefox > Quit")

  • I just upgraded my iMac to Lion, and a few seconds ago, I upgraded the iWork package and now I'm having some problems with the new version of Pages (4.1) When I try to change something in a document, a message says "the program is not responding"

    I just upgraded my iMac to Lion, and a few seconds ago, I upgraded the iWork package and now I'm having some problems with the new version of Pages (4.1) When I try to change something in a document, a message says "the program is not responding", so I have to force it to close. By the way, the SAVE botton stays the same even I change erverything in my document. Please, a have a work to finish, **** me. What I can do abou it?

    I just upgraded my iMac to Lion, and a few seconds ago, I upgraded the iWork package and now I'm having some problems with the new version of Pages (4.1) When I try to change something in a document, a message says "the program is not responding", so I have to force it to close. By the way, the SAVE botton stays the same even I change erverything in my document. Please, a have a work to finish, **** me. What I can do abou it?

  • Dunning letters generation when customer address is changed

    Hi,
    For some customers no dunning letters were generated. After investigation inactive bill-to site should be activated as invoices were assigned to this bill-to.
    How is possible to make that dunning letters generated when customer address is changed and customer can receive letters to new address for all its invoices?
    Any help will be appreciated!
    BR, JC

    hi
    I have created one sales order example X and i created the another sales order Y with respect to X
    Is this X sales document is closed????
    And I also changed the address of the ship to party in sales document Y.
    Did you assgined another SP to sales Document Y
    If you have chnaged the address for SP in customer master then it will reflect to both
    Also it will not chnage the ADRESS NO in VBPA table, but it will update the address

  • I have an old Apple ID connected to a discontinued e-mail address.  I want to delete it.  I cannot remember my password and when I try to change the password using the security questions, it rejects my birth date!  I can't change it by cancelled e-mail.

    I have an old Apple ID associated with a discontinued e-mail address.  It keeps popping up when I try to update apps.  I don't remember the password.  When I try to change it by security questions, it rejects my birthdate!  I can't change it by e-mail because I no longer have access to the e-mail.  All I really want to do is cancel this old ID.  How can I do this?  Obviously, I have a new ID, since I am using this support community.

    You'll have to contact iTunes store support to see if they can help you with this: http://www.apple.com/emea/support/itunes/contact.html.

  • How do I quickly update the ActiveX automation references in my VIs when the ActiveX interface changes?

    Hello all,
    I joined a test automation team in the middle of a large project and
    inherited a huge set of VIs (over 700) and associated architecture for
    this automation (not to mention the several thousand TestStand
    sequences).  Another part of the project is being developed by our
    customer, who is using VB 6.0 to create ActiveX components which we
    need to use in LabView to access their hardware.  They've already
    invested a large amount of time developing these ActiveX components,
    and they are not finished -- meaning the ActiveX interfaces will be
    changing.  Every time they send updated ActiveX components, I have to
    re-write many, many VIs including updating a couple strict typdefs. 
    This process takes way too much time and is mind-numbing and prone to
    error or omission.
    Unfortunately I can't post any of the VIs because of a NDA.  But
    perhaps a bit more detailed explanation would help.  TestStand calls a
    VI to open and get an ActiveX reference for automation (which it stores
    in a variant).  It will pass this reference into any VI it calls to
    perform specific functions through this ActiveX interface.  For
    example, one VI that may be called passes this automation refnum into
    another, which passes it to another, which passes it into another to
    get the actual ActiveX reference stored in that variant (through a
    Variant To Data call with a strict typedef of the ActiveX component
    wired to the type input).  [See the attached image of this sample VI
    hierarchy: the far left icon would represent TestStand, and the far
    right is the strict typedef.]  Any of the VIs in the chain might use
    ActiveX Property or Invoke nodes, and it can break at any one of those
    when the ActiveX component changes.  It's easy to fix each one, but
    since there are so many VIs it takes a very long time.
    Is there any way at all to do a massive search/replace or something to
    make the ActiveX references update?  I realise that even though
    property or method names stay the same from one version to the next,
    they are different references.  Is there a way to update these based on
    name if you give it the base ActiveX reference?
    Thanks in advance for any help!
    Tom Williams
    Attachments:
    hierarchy.GIF ‏6 KB

    Ben,
    Unfortunately I can't post any VIs that would demonstrate the problem
    because the ActiveX components are confidential.  I'll try to develop
    my own ActiveX dll that will demonstrate it, but in the meantime, in
    hopes that another picture will help, I've attached an image of a block
    diagram (with some names changed to protect confidential information)
    of one of the lower level VIs from the hierarchy I posted.  In this
    example, the "Automation Refnum IN" is an input with a type definition
    linked to the strict typedef based on the ActiveX automation dll that
    has changed.  I updated that typedef, but as you can see the output to
    the "Class1" indicator is broken.  If I delete the "Class1" indicator
    and select Create->Indicator from the Class1 property node, and then
    wire the new "Class1" indicator to the connector pane, the VI is fixed
    -- at least at compile time.  In most cases there is also a runtime
    problem where the reference obtained by one of the intermediate
    property nodes is null, so the property or method node that uses it
    fails (e.g. "_VNManager.Networks" property returned is 0, so the
    "_Networks.Network1" property node fails).  To fix this problem, I have
    to delete the wires between the property nodes, and one by one select a
    different property/method, then select the correct property/method and
    re-wire.  There seems to be a bit of "jiggling the handle" to get it to
    work though.
    I don't know if the ActiveX developer changed anything in this class,
    but if he did, he didn't change the name of this class.  I would like
    to have to modify the VI only if a class, property or method has
    changed name or been removed.
    Does that all make sense?  Thanks for any pointers or help!
    Tom
    Attachments:
    Class1_Path.GIF ‏7 KB

  • HT1311 I have two Apple IDs, one with all my purchases and info on it. The one with everything on it is under a bad email address. When I tried to change it to my current email, it tells me I already have an account. How do I fix this?

    I had an old iPod under an old Apple ID  which was stolen. I replaced it with an iPhone and apparently created a new Id under my current email address. When i went to sync the phone to my comuter (several months later), I accidentally restored the phone to my old iPod settings and lost everything.  I then continued to make purchases on the phone but didn't realize that it had reverted back to my old Apple ID. This is under an old email that I no longer have access to. When I tried to change the Apple ID/email address in the account settings, it won't let me because it says that there is already an Apple ID under this address. However, all my information (settings, contacts, photos, aps) are under an incorrect email. How can I change the account I have been using to reflect my valid current email address if there is already an existing account (which I never really used) under this address? Please, I don't want to lose all my info again.

    Change the email on the old account to another new, current email address.
    An email address can only be linked to one Apple ID.
    It is possible to have content from multiple Apple ID's on a single iDevice.

  • Can't get and use an apple id for cloud or apps or store when i try to change it it will let me but then everytime it keeps asking me to chang e password everytime cant get my computer to just accept one password that will keep

    can't get and use an apple id for cloud or apps or store when i try to change it it will let me but then everytime it keeps asking me to chang e password everytime cant get my computer to just accept one password that will keep

    Just what are you doing and what is the exact wording of the message you are getting?

Maybe you are looking for