Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8227197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:02:42+00:00 2026-06-07T16:02:42+00:00

I’m having a problem. I’m reading data from a socket, and when I read

  • 0

I’m having a problem. I’m reading data from a socket, and when I read some meaningful data to my app I call a method to repaint the screen with the swing objects I want. This method works all right excepts that sometimes it does not appear. Nothing on the screen on the very first time the method is called (I already ran the debug and it passes all through the method). The stupid part is that, if I minimize and maximize the app it works fine again. Besides, if the method is executed again it works fine to. I’ll put the code here just for documentation:

public void GraphicONENodeJoined (Nodes NodesList)
 {
     SensorsMapGraf [] sensorsMap;
     boolean FLAG;
     int ymin=0, ymax=30;
     FLAG = TabExistingNode_NEW_nodeRefresh (NodesList);
     if (FLAG)
     {
         ValorTeste++;
         if (ValorTeste > 1)
         {
             String [] s = new String[ValorTeste];
             JButton [] jbb = new JButton[ValorTeste];
             JCheckBox [] ch = new JCheckBox[ValorTeste];
             for (int i=0 ; i < ValorTeste-1 ; i++)
             {
                 s[i] =  nods[i];
                 jbb[i] = jb[i];
                 ch[i] = CheckBoxNodes[i];      
             }
             jb = new JButton[ValorTeste];
             CheckBoxNodes = new JCheckBox[ValorTeste];
             nods =  new String[ValorTeste];

             for (int i=0 ; i < ValorTeste ; i++)
             {
                 nods[i] = s[i];
                 jb[i] = jbb[i];

                 CheckBoxNodes[i] = ch[i];
             }       
         }

            nods[ValorTeste-1]+= NodesList.GETSourceNodeID();
            //PARA FAZER O UPDATE DAS TABS E DOS GRÁFICOS
            JPanel meio = new JPanel();         //JPanel que contem os graficos de cada sensor

            String s = new String();
            s += NodesList.GETSourceNodeID();

            JPanel meio_cima = new JPanel();    //JPanel que contem  o botão view (permitirá escolher quais os sensores a ver)
            meio_cima.setAlignmentX(LEFT_ALIGNMENT);
            meio_cima.setPreferredSize(new Dimension(dim.width, 25));
            meio.setBounds (pan1.getBounds());
            GridBagLayout g = new GridBagLayout();
            GridBagConstraints c = new GridBagConstraints();

            meio.setLayout(g);
            meio.setOpaque(true);
            //botão view (permitirá escolher quais os sensores a ver)
            jb[nods.length-1] = new JButton("View");
            jb[nods.length-1].setPreferredSize(new Dimension(100,20));
            jb[ValorTeste -1].addActionListener(this);
            meio_cima.add(jb[ValorTeste-1]);
            //Panel qu albergará o panel meio e o panel meio_cima
            JPanel principal = new JPanel();
            //inicia o array de sensores que cada Tab tem de mostrar
            sensorsMap = new SensorsMapGraf[NodesList.GETnumSensoresActivos()];

            int indice = 0;
            for (int j=0 ; j < 12 ; j++)
            { 
                //nicely to view in the graphics
                if ((j == 0) || (j == 1) || (j == 2) || (j == 3) || (j == 6) || (j == 7))
                {
                    ymin = 0;
                    ymax = 3;
                }
                if (j == 8)
                {
                    ymin = 0;
                    ymax = 100;
                }
                if (j == 9)
                {
                    ymin = 0;
                    ymax = 100;
                }
                if (j == 10)
                {
                    ymin = 0;
                    ymax = 4;
                }
                if (j == 11)
                {
                    ymin = 0;
                    ymax = 130;
                }
                if (j == 4 )
                {
                    ymin = 0;
                    ymax = 6000;
                }
                if (j == 5)
                {
                    ymin = 0;
                    ymax =700;
                }

                if (NodesList.GETSensores(j).GETligado()) // se estiver ligado
                {
                    //panel que albergará o grafico 
                    JPanel p = new JPanel();
                    p.setBounds(meio.getBounds());

                    if (NodesList.GETnumSensoresActivos() <= 4)
                    {
                        if (NodesList.GETnumSensoresActivos() <= 4  && NodesList.GETnumSensoresActivos() > 1)
                            sensorsMap[indice] = new SensorsMapGraf(true,NodesList.GETSensores(j).GETnome(),NodesList.GETSensores(j).GETunidade(),meio.getBounds(),(int)meio.getWidth()/2-20,(int)meio.getHeight()/2-20,ymin,ymax); // cria o sensor
                        else
                            sensorsMap[indice] = new SensorsMapGraf(true,NodesList.GETSensores(j).GETnome(),NodesList.GETSensores(j).GETunidade(),meio.getBounds(),(int)meio.getWidth()/NodesList.GETnumSensoresActivos(),(int)meio.getHeight()/NodesList.GETnumSensoresActivos()-35,ymin,ymax); // cria o sensor
                    }

                    if (NodesList.GETnumSensoresActivos() > 4 && NodesList.GETnumSensoresActivos() <= 8)
                        sensorsMap[indice] = new SensorsMapGraf(true,NodesList.GETSensores(j).GETnome(),NodesList.GETSensores(j).GETunidade(),p.getBounds(),(int)meio.getWidth()/4-15,(int)meio.getHeight()/2 - 45,ymin,ymax); // cria o sensor

                    if (NodesList.GETnumSensoresActivos() > 8 && NodesList.GETnumSensoresActivos() <= 12)
                        sensorsMap[indice] = new SensorsMapGraf(true,NodesList.GETSensores(j).GETnome(),NodesList.GETSensores(j).GETunidade(),p.getBounds(),(int)meio.getWidth()/4-20,(int)meio.getHeight()/3-35,ymin,ymax); // cria o sensor

                        if (indice == 0)
                        {
                            c.fill = GridBagConstraints.HORIZONTAL;
                            c.gridx = 0;
                            c.gridy = 0;
                            meio.add(sensorsMap[indice].GetGraph().GETDemoPanel(),c);  //adidionar o panel p ao panel meio
                        }
                        if (indice == 1)
                        {
                            c.fill = GridBagConstraints.HORIZONTAL;
                            c.gridx = 1;
                            c.gridy = 0;
                            meio.add(sensorsMap[indice].GetGraph().GETDemoPanel(),c);  //adidionar o panel p ao panel meio
                        }
                        if (indice == 2)
                        {
                            c.fill = GridBagConstraints.HORIZONTAL;
                            if (NodesList.GETnumSensoresActivos() <= 4)
                            {
                                c.gridx = 0;
                                c.gridy = 1;
                            }
                            else
                            {
                                c.gridx = 2;
                                c.gridy = 0;
                            }
                            meio.add(sensorsMap[indice].GetGraph().GETDemoPanel(),c);  //adidionar o panel p ao panel meio
                        }
                        if (indice == 3)
                        {
                            c.fill = GridBagConstraints.HORIZONTAL;
                            if (NodesList.GETnumSensoresActivos() > 4)
                            {
                                c.gridx = 3;
                                c.gridy = 0;
                            }
                            else
                            {
                                c.gridx = 1;
                                c.gridy = 1;
                            }
                            meio.add(sensorsMap[indice].GetGraph().GETDemoPanel(),c);  //adidionar o panel p ao panel meio
                        }
                        if (indice == 4)
                        {

                            c.fill = GridBagConstraints.HORIZONTAL;
                            c.gridx = 0;
                            c.gridy = 1;
                            meio.add(sensorsMap[indice].GetGraph().GETDemoPanel(),c);  //adidionar o panel p ao panel meio
                        }
                        if (indice == 5)
                        {
                            c.fill = GridBagConstraints.HORIZONTAL;
                            c.gridx = 1;
                            c.gridy = 1;
                            meio.add(sensorsMap[indice].GetGraph().GETDemoPanel(),c);  //adidionar o panel p ao panel meio
                        }
                        if (indice == 6)
                        {
                            c.fill = GridBagConstraints.HORIZONTAL;
                            c.gridx = 2;
                            c.gridy = 1;
                            meio.add(sensorsMap[indice].GetGraph().GETDemoPanel(),c);  //adidionar o panel p ao panel meio
                        }
                        if (indice == 7)
                        {
                            c.fill = GridBagConstraints.HORIZONTAL;
                            c.gridx = 3;
                            c.gridy = 1;
                            meio.add(sensorsMap[indice].GetGraph().GETDemoPanel(),c);  //adidionar o panel p ao panel meio
                        }
                        if (indice == 8)
                        {
                            c.fill = GridBagConstraints.HORIZONTAL;
                            c.gridx = 0;
                            c.gridy = 2;
                            meio.add(sensorsMap[indice].GetGraph().GETDemoPanel(),c);  //adidionar o panel p ao panel meio
                        }
                        if (indice == 9)
                        {
                            c.fill = GridBagConstraints.HORIZONTAL;
                            c.gridx = 1;
                            c.gridy = 2;
                            meio.add(sensorsMap[indice].GetGraph().GETDemoPanel(),c);  //adidionar o panel p ao panel meio
                        }
                        if (indice == 10)
                        {
                            c.fill = GridBagConstraints.HORIZONTAL;
                            c.gridx = 2;
                            c.gridy = 2;
                            meio.add(sensorsMap[indice].GetGraph().GETDemoPanel(),c);  //adidionar o panel p ao panel meio
                        }
                        if (indice == 11)
                        {
                            c.fill = GridBagConstraints.HORIZONTAL;
                            c.gridx = 3;
                            c.gridy = 2;
                            meio.add(sensorsMap[indice].GetGraph().GETDemoPanel(),c);  //adidionar o panel p ao panel meio
                        }
                    indice++;
                }
            }

            //adicionar o meio_cima e o meio panel principal
            principal.add(meio_cima);
            principal.add(meio);

            Tabs.addTab(s, principal); // adicionar tab
            String ss = new String();
            ss += NodesList.GETSourceNodeID();

            GraphicsMap.add(new CentralMap(ValorTeste-1, ValorTeste-1, sensorsMap,ss,NodesList.GETLogicalNodeID()));  // adição de uma Tab
            GraphicsMap.get(ValorTeste-1).SetnumSensorsToShow(NodesList.GETnumSensoresActivos());

            posx = 20;
            posy = 20;

            CheckBoxNodes[ValorTeste-1] = new JCheckBox(s);
            CheckBoxNodes[ValorTeste-1].setBackground(null);
            CheckBoxNodes[ValorTeste-1].setLayout(new GridLayout(ValorTeste, 1, 0, 30));
            CheckBoxNodes[ValorTeste-1].setBounds(posx, posy, aux1-60, 30);
            CheckBoxNodes[ValorTeste-1].setSelected(false);
            CheckBoxNodes[ValorTeste-1].setOpaque(true);
            CheckBoxNodes[ValorTeste-1].setVisible(true);

            //Evento a tratar
            CheckBoxNodes[ValorTeste-1].addItemListener (this);

            pan3.add (CheckBoxNodes[ValorTeste-1]);
            pan1.add (Tabs);
     }
  }

I already tried to repaint pan2 but it didn’t do anything.

thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:02:46+00:00Added an answer on June 7, 2026 at 4:02 pm

    You’re posting a lot of code completely unrelated to the problem, and confusing code at that, but it sounds as if you may have a Swing concurrency issue. Be sure to do the reading in of data on a background thread and the writing to the Swing components on the Swing event thread or EDT. For better help though, post code relevant to the problem. An sscce would work best.

    Also, if adding or removing components from a GUI, be sure to call revalidate() on the container and then repaint().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
We're building an app, our first using Rails 3, and we're having to build
I am currently running into a problem where an element is coming back from
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.