Updating components in jpanel

Hi, all
I have a report application which will update me system utilization in several jpanel. Those panels stored in a hashtable and I programmed it refresh each 5 minutes. Here is how I do it.
Step 1: remove all
mypanel=(JPanel)panels.get("1");
mypanel.removeAll();
mypanel.validate();
Step 2: show progress
mypanel.add(<updating message in jlabel>);
mypanel.add(<a progressbar>);
mypanel.validate();
Step 3: add new content
mypanel.removeAll();
mypanel.add(<a graph in jlabel>);
mypanel.add(<a jtable with data>);
The problem is the old content still remains when progress bar appeared. Didn't I just remove all components in step 1? How can I have a empty panel with only progress bar?
Thanks,
Vincent Chen

Damn, I found what the problem is, but if I gave the solution to the OP, that would mean confessing I have followed the link, and admitting to belong to the "not worth mentioning" category!Well, since my cover's blown anyway, let's caugh it up:
Your have an attrubute searchType of type SearchType, you initialize it to reference a new SeearchType() , and you use its status for the search, however you never add the instance in the panel's widget hierarchy. Instead you add a new SearchType() .
Same for attribute style :
searchType = new SearchType();
style = new Style();
this.add(new SearchType(), c);
this.add(new Style(), c);
// in event handler
search(txfQuery.getText(),searchType.getSelected(),style.caseSensitive(),limitation.getLimNum());
                                ^
                                *At this point, the instance referenced by searchType has never been displayed, so the checkbox, combobox, and whatnot that the user has interacted with are not the ones whose state you read.

Similar Messages

  • Downloading the 10.6.8 Update Combo v1.1 and it seems stuck at "registering updated components". It's running but I've had "about a minute" left for 30 minutes now

    Trying to download the 10.6.8 Update Combo v1.1 and it seems stuck at "Registering updated components". It's been saying it has "about a minute" left for at least a half hour. What do I do?

    Try downloading it from the Apple site.  Set Safari to download to the desk top:Safari preferences>general>save downloads to desktop.  Download to desktop, and run the installer:
    http://support.apple.com/kb/DL1399

  • Can't show J components on JPanel

    Because I'm a begineer, I'm not sure I can explain my problem correctly.
    The problem is quite simple.
    I'd like to show some J components on JPanel but I can't.
    I made a JFrame which has 5 JPanels.
    Each JPanel has some components and calls paint method to draw some lines.
    public void paint(Graphics g){
         g.setColor(Color.black );
         drawDisplay(g);
    When I put AWT componts such as Label, Button etc, there's no problem.
    But when I put J components like JLabel, JButton,
    I cannot see the components. Sometimes I can click JCombo box....
    Interestingly, when I remove the paint method, J components show up on interface.
    Anybody understand this situation?
    Do I have to know something for this?
    Thank-you.

    I second camickr's recommendation for you to study the tutorials. A few specifics:
    public void paint(Graphics g){
       g.setColor(Color.black );
       drawDisplay(g);
    }* Don't override the paint method of a JPanel, override the paintComponent method.
    * You will need to call super.paintComponent(g) within your paintComponent override. This may need to be the first line in fact.
    * As noted by camickr, do not place AWT components on a Swing component (JPanel).

  • How can we add components to JPanel so that they can be resizeable

    Is it possible to add components to JPanel so that we can resize them or drag them.

    You could try searching the forums, but I'll save you the trouble. tjacobs has oft posted code which does what you want, both dragging and resizing.
    You can find an example here or here.

  • Unable to install or start phone software update components -Arc S

    I cannot update my xperia arc S. It always ended up showing this "
    Unable to install or start phone software update components". Can anyone, help me?
    Solved!
    Go to Solution.

    SUS ( Sony Update Service)  ... download and install it on pc and follow the on-screen instructions http://www-support-downloads.sonymobile.com/Software%20Downloads/Update_Service_Setup-2.11.12.5.exe
                      or
    http://www.sonymobile.com/global-en/tools/update-service/
    Both the links are same
    Discussion guidelines.
    Message me or any other moderator to seek help regarding moderation.

  • Clusters available in update components software library

    Hi Experts,
    How do the Solaris patch clusters available in the update components software library compare to the Critical Patch Update cluster released by Oracle? The clusters available in OC seem to reflect more than one per month. I’m not used to dealing with patch clusters in this way as before using OC; we’d manually apply patches to our servers using the latest recommended Critical Patch Update available for download on MOS which are released quarterly.
    Thanks,
    DJC

    @ytheekshana
    Since the update is just being rolled out, you will need to use PCC or Bridge for Mac, this is based on other updates on other phones, there isn't an specific date as to when it'll be released OTA.
    "I'd rather be hated for who I am, than loved for who I am not." Kurt Cobain (1967-1994)

  • How can I update components position after a setSize call?

    Hi there. I need some help. I have a JFrame application. When you press a button, the JFrame size changes, but the components added to it keep in the same position, they dont update to the new size, until I change manually the size of the JFrame, with the mouse. How can I make they to update automatically when I call the setSize(20,40) ?
    Thank you!
    The code:
    public void actionPerformed( ActionEvent event )
    setSize(300,90);
    repaint();
    }

    Thank you Encephalopathic for your answer. I try calling revalidate() but it still doesnt work. The SSCCE is here:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Panel extends JFrame implements ActionListener {
         private JPanel panel1;
         private JPanel panel2;
         private JButton btn1;
         private JButton btn2;
            private Container container;
         public Panel(){
                 super( "Title" );
                btn1 = new JButton( "Resize");
                btn2 = new JButton( "btn2");
                btn1.addActionListener(this);
                panel1 = new JPanel();
                panel2 = new JPanel();
                      panel1.add(btn1);
                panel2.add(btn2);
                      container = getContentPane();
                container.add(panel1);
                setSize(315,325);
                      setVisible(true);
         public void actionPerformed( ActionEvent event ){
                   setSize(100,100);
                      container.remove(panel1);
                   container.add(panel2);
                      panel2.revalidate();   // doesnt work
                container.validate(); // doesnt work
         public static void main (String args[]){
                   Panel panel = new Panel();
    }Edited by: gasbor on Feb 28, 2009 10:09 PM

  • Sticking components in JPanel to GridLayout

    Could please anyone help in the following.
    I have an application where some JPanel with several Swing components
    positioned with help of GridLayout. What I need is to
    remove and place components during runtime,
    but the problem is that when I remove component placed somewhere
    inbetween with use of the method remove() of the class JPanel,
    all components are shifted so that the empty space is filled and
    even one can see that the initial GridLayout is destroyed.
    How can I stick all components to the initial grid cells of GridLayout?
    I mean I do not want components to shift anywhere from their original
    cells.
    Thank you in advance.

    Well, that solution is what I came to also.
    I mean I replacing removed compenent with some other invisible component.
    But is this indeed the only way?
    I tryied the method removeLayoutComponent() in the class GridLayout, but
    I have not understood how it works and what it is for.
    When I tryied it instead of remove() (of JPanel) it did not remove anything,
    but it looks like something relevant to my situation.
    PS The second line of my orginal poster should be read
    "I have an application where some JPanel is created with several Swing components
    positioned with help of GridLayout in it".
    Sorry...

  • Redisplaying jFrame with updated components

    I have an object A that instantiates object B.
    My object name is B_Object.
    I call B_Object.setVisible(true);
    (This is basically a jframe with jpanel with empty jScrollPane)
    Later on, I call B_Object.redisplay() which I want to add components into my jScrollPane and redisplay the jFrame with the new information in the jScrollPane. However, it doesn't display everything in my jScrollPane. It looks like it wants to, but doesn't.
    Is this a thread problem? Or I can't just recreate a jFrame that I already have it visible?

    When you add or remove a component from a Container, then you need to revalidate() the container so the Layout Manager can be invoked.

  • How to change properties or add components in JPanel after initialization ?

    Hi,
    I am working on an applet where an image will be loaded in a JPanel from an URL. The JPanel is inside a JscrollPane.
    1.The image will be added on the JPanel later , not during initialization.
    2. JPanel size will be the size of the image.
    3 .the image size may change when the image is changed. Then the JPanel size also has to be updated.
    FYI I am using MediaTracker to load the image.
    I was trying updateUI() for scrollPane. But it is not working.
    How can I do it? Any suggestion?
    Thanks in advance.

    I have to use JPanel because I need flexible control on the imageYou said previously that the panel was the size of the image, so I don't understand what kind of flexible control you are talking about. Presumably you have code in the paintComponent(...) method of the JPanel something like:
    g.drawImage(0, 0, width, height)
    Well that is exactly what a JLabel would do.
    So if you need further custom painting then you would just override the paintComponent(...) method of JLabel to do your custom painting.

  • Update picture in JPanel

    i'm have a picture, i showed it in JPanel, but my picture is change at any time, how i can update new picture on JPanel when my picture is updated
    //add picture in JPanel
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.JPanel;
    class ImagePanel extends JPanel {
        private Image img;
        public ImagePanel(Image img) {
            this.img = img;
            Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
            setPreferredSize(size);
            setMinimumSize(size);
            setMaximumSize(size);
            setSize(size);
            setLayout(null);
        public void paintComponent(Graphics g) {
            g.drawImage(img, 0, 0, null);
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import java.rmi.Naming;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    public class ShowClient extends JFrame implements MouseMotionListener{
        public ShowClient() {
            super("Control Client");
            UpdatePicture();
        //this method
        public void UpdatePicture(){
            ImagePanel panel =
                    new ImagePanel(new ImageIcon("screen.jpg").getImage());
            JScrollPane scrollPane = new JScrollPane(panel);
            this.setLayout(new BorderLayout());
            this.add(scrollPane, BorderLayout.CENTER);
            scrollPane.addMouseMotionListener(this);
              when mouser move will have a new picture.
        public void mouseMoved(MouseEvent e){
            int x = e.getX();
            int y = e.getY();
            EventServer event = null;
            try {
                event = (EventServer)Naming.lookup("//localhost/Client");
                event.MouseMove(x, y);
            catch (Exception exp){
                System.out.println("Err " + exp);
            UpdatePicture(); //why here my JPanel don't show new picture
        public void mouseDragged(MouseEvent e){
        public void Show(){
            this.setDefaultCloseOperation(HIDE_ON_CLOSE);
            Toolkit tool = Toolkit.getDefaultToolkit();
            Dimension size = tool.getScreenSize();
            this.setSize(size);
            this.setVisible(true);
    }Thank a lot of !!
    Edited by: bathong on May 23, 2009 10:39 AM

    >
    If you mean that the image file is updated, you will need to either reload the Image from the file using ImageIO#read(...) or flush() the Image.
    When you load the image using the ImageIcon constructor that takes a String parameter, it is cached by Toolkitand will not be reloaded even if the file content changes.
    Why create an ImageIcon just to retrieve its Image? Use ImageIO and just load an Image.
    db
    >
    I rewrite as :
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import javax.swing.JPanel;
    class ImagePanel extends JPanel {
        public BufferedImage img;
        public ImagePanel(BufferedImage img) {
            this.img = img;
            Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
            setPreferredSize(size);
            setMinimumSize(size);
            setMaximumSize(size);
            setSize(size);
            setLayout(null); 
        public void paintComponent(Graphics g) {
            g.drawImage( img, 0, 0, null);
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionListener;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.rmi.Naming;
    import javax.imageio.ImageIO;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    public class ShowClient extends JFrame implements MouseMotionListener{  
        public ShowClient() {
            super("Control Client");
            UpdatePicture();
        public void UpdatePicture(){
            try { 
                File file = new File("screen.jpg");
                BufferedImage buff = ImageIO.read(file);
                ImagePanel panel = new ImagePanel(buff);
                JScrollPane scrollPane = new JScrollPane(panel);
                this.setLayout(new BorderLayout());
                this.add(scrollPane, BorderLayout.CENTER);
                scrollPane.addMouseMotionListener(this); 
            catch (Exception exp){
                System.out.println("Error here " + exp);
                exp.printStackTrace();
        public void mouseMoved(MouseEvent e){
            int x = e.getX();
            int y = e.getY();
            EventServer event = null;
            try {
                event = (EventServer)Naming.lookup("//localhost/Client");
                event.MouseMove(x, y);
            catch (Exception exp){
                System.out.println("Err " + exp);
            UpdatePicture();
        public void mouseDragged(MouseEvent e){
        public void Show(){
            this.setDefaultCloseOperation(HIDE_ON_CLOSE);
            Toolkit tool = Toolkit.getDefaultToolkit();
            Dimension size = tool.getScreenSize();
            this.setSize(size);
            this.setVisible(true);
    }but new picture also can't update!! please help me, thank !!!!

  • Zooming causes components on JPanel to displace

    Hi friends,
    my english is somewhat weak, but i am trying to clear my point.
    I have a prob regarding zoom. In my application I have A JPanel which is drawing some rectangles on it and having some JLabels. My prob is when i zoomin my JPanel through my zooming code and try to select any of JLabel ,I am not actually selecting labels by just clicking on the label but i have to make some random guess on JPanel to select that label.
    I am not getting what mistake i m making there. may be i would have to move my labels by some distance on zooming(but its only my view). if any of you have some ideas then please do tell me.
    thankyou

    I second camickr's recommendation for you to study the tutorials. A few specifics:
    public void paint(Graphics g){
       g.setColor(Color.black );
       drawDisplay(g);
    }* Don't override the paint method of a JPanel, override the paintComponent method.
    * You will need to call super.paintComponent(g) within your paintComponent override. This may need to be the first line in fact.
    * As noted by camickr, do not place AWT components on a Swing component (JPanel).

  • Handling focus on components within JPanel

    I have a custom component called a DmsField which extends JPanel. "Dms" means degrees/minutes/seconds. It's a JPanel with a two-button JRadioButton group for the sign, and three JFormattedTextFields for degrees (int), minutes (int), and seconds (float, 2 dec places). It's later subclassed into LatField and LonField so I can enter latitudes and longitudes into an application. When I put a LatField or a LonField into my dialog's JPanel, tabbing through the various components in the larger panel shifts the focus to the whole LatField (or LonField) object first, then through the subobjects in the *Field.  How can I get the focus traversal to NOT focus on the DmsField itself, but to go straight to the first component inside the DmsField?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I have tried putting a FocusListener on the JPanel which would set the focus to its first component. Works fine tabbing forward, but gets stuck on first component when back-tabbing.
    Disabling FOCUS_EVENT_MASK on the JPanel didn't change anything.
    The odd thing is, I don't see any other JPanels exhibiting this behavior.

  • Re-order components in JPanel using Drag and Drop

    Hi,
    I have a JPanel that contains some more JPanels (the Layout is GridBagLayout - one column, each row - 1 JPanel). I would like to drag one JPanel (1) and after dropping it on some other JPanel (2), the (1) should be inserted at (2)'s position.
    I really can't get the idea from sun's tutorials :(

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class DragTest extends JPanel
        public DragTest()
            setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(5,5,5,5);
            gbc.weighty = 1.0;
            gbc.weightx = 1.0;
            gbc.fill = GridBagConstraints.BOTH;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            for(int j = 0; j < 4; j++)
                JPanel panel = new JPanel(new BorderLayout());
                panel.setBorder(BorderFactory.createEtchedBorder());
                panel.add(new JLabel("panel " + (j+1), JLabel.CENTER));
                add(panel, gbc);
        public static void main(String[] args)
            DragTest test = new DragTest();
            DragListener listener = new DragListener(test);
            test.addMouseListener(listener);
            test.addMouseMotionListener(listener);
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(test);
            f.setSize(400,400);
            f.setLocation(200,200);
            f.setVisible(true);
    class DragListener extends MouseInputAdapter
        DragTest dragTest;
        Component selectedComponent;
        GridBagConstraints constraints;
        Point start;
        boolean dragging;
        final int MIN_DRAG_DISTANCE = 5;
        public DragListener(DragTest dt)
            dragTest = dt;
            dragging = false;
        public void mousePressed(MouseEvent e)
            Point p = e.getPoint();
            Component[] c = dragTest.getComponents();
            for(int j = 0; j < c.length; j++)
                Rectangle r = c[j].getBounds();
                if(r.contains(p))
                    selectedComponent = c[j];
                    start = p;
                    dragging = true;
                    break;
        public void mouseReleased(MouseEvent e)
            if(dragging)  // no component has been removed
                dragging = false;
                return;
            Point p = e.getPoint();
            if(!dragTest.getBounds().contains(p))  // out of bounds
                // failed drop - add back at index = 0
                dragTest.add(selectedComponent, constraints, 0);
                dragTest.revalidate();
                return;
            Component comp = dragTest.getComponentAt(p);
            int index;
            if(comp == dragTest)
                index = getDropIndex(dragTest, p);
            else  // over a child component
                Rectangle r = comp.getBounds();
                index = getComponentIndex(dragTest, comp);
                if(p.y - r.y > (r.y + r.height) - p.y)
                    index += 1;
            dragTest.add(selectedComponent, constraints, index);
            dragTest.revalidate();
        private int getDropIndex(Container parent, Point p)
            Component[] c = parent.getComponents();
            for(int j = 0; j < c.length; j++)
                if(c[j].getY() > p.y)
                    return j;
            return -1;
        private int getComponentIndex(Container parent, Component target)
            Component[] c = parent.getComponents();
            for(int j = 0; j < c.length; j++)
                if(c[j] == target)
                    return j;
            return -1;
        public void mouseDragged(MouseEvent e)
            if(dragging)
                if(e.getPoint().distance(start) > MIN_DRAG_DISTANCE)
                    // save constraints for the drop
                    GridBagLayout layout = (GridBagLayout)dragTest.getLayout();
                    constraints = layout.getConstraints(selectedComponent);
                    dragTest.remove(selectedComponent);
                    dragging = false;
                    dragTest.revalidate();
    }

  • Unable to install or start phone software update components

    Hi,
    Had this problem just now after searching forum did not find a fix but worked it out myself, heres how:
    Goto > C:\ProgramFiles\SonyEricsson
    Then just delete the update engine folder, restart update , and bosh it works!
    thought this might be helpful to those with same issue, maybe even make it a sticky :smileywink:

    I suggest you try the following,
    1. Close PC Companion
    2. Install java from http://www.java.com/winoffline_installer
    3. Start PC Companion again and try to do the SW Update of the phone.
     - Official Sony Xperia Support Staff
    If you're new to our forums make sure that you have read our Discussion guidelines.
    If you want to get in touch with the local support team for your country please visit our contact page.

Maybe you are looking for

  • "Backing Up" Before Writing to the Console

    I am writing a program that uses the console for both input and output. Input comes from a seperate thread and could come at any time, even while the users is typing something. If this happens, then whatever is written to System.out gets tagged on to

  • Multiple Ports & Mobility Groups

    On our wireless network we have two 6509-E switches each with a WiSM and a 5508 WLC. The 5508 WLC only had one port connected to one of the 6509 units then we added another port on the 5508 to the other 6509. Do I need to add the IP and MAC address o

  • Help needed during generation of ILDT file using irep_parser.pl

    The is is my package which I have annotated REATE OR REPLACE PACKAGE Xxetc_Soa_Req_Apps_Pkg  AS /* $Header: XXETC_SOA_REQ_APPS_PKG .pkb 1.0 2014/03/04 $ */ * This custom PL/SQL package * @rep:scope public * @rep:product CUSTOM * @rep:lifecycle active

  • How to join three or more blocks in a form (like master/detail)

    I have four data blocks for four tables, lets call them blocks A, B, C, D Block A is a master block and block B is a detail block, block B holds a foreign key from block A (ofcourse) Now when i choose in a query data from block A it lists also data f

  • How to retrieve photos & messages from old back-up without loosing current photos & messages

    I gave my old iphone to my technophobic mum. She used it happily until it died early this year. I gave her another iphone, but I think that I set it up as a new iphone on her itunes account. she has been using it for a few weeks, but can't send MMS m