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 7556815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:57:35+00:00 2026-05-30T11:57:35+00:00

I made some menu and it is to update conmmon variables (for text on

  • 0

I made some menu and it is to update conmmon variables (for text on grid) then the out-of-focus dialog must repaint the grid. Here is the screenshot:

enter image description here

The main control panel is always at top position and ‘Data Display’ panel is always sitting behind it. When press a button on front panel, Data Display must update its grid. Currently, the common variable 0.4 on the grid is updated by adding listener and works fine. But the grid itself is not repainting anymore. How can I repaint the out-of-focus dialog in real time?

Here is the code of the front panel:

public class MainDisplayForm extends javax.swing.JFrame {

Storage st = new Storage();
DisplayForm dF = new DisplayForm();
....
public MainDisplayForm() {
    initComponents();
    Btn_IncreaseGain.addActionListener(new ButtonListener_IncreaseGain());
}
....
} //MainDisplayForm ends here.

class ButtonListener_IncreaseGain implements ActionListener {

DisplayForm dF = new DisplayForm();
Storage st = new Storage();

ButtonListener_IncreaseGain()
{

}

public void actionPerformed(ActionEvent e) {    

    st.iGain = 20;

    dF.revalidate();
    dF.repaint();
    System.out.println("Testing"); 
    }
}//Listener ends here.

Here is code of Data Display:

public void paint(Graphics g)
{        
    g2 = (Graphics2D) g;
    paintComponents(g2);

    //added numbers are for adjustment.
    int x = this.jPanel1.getX()+8;
    int y = this.jPanel1.getY()+30;
    int width = this.jPanel1.getWidth()+19;
    int height = this.jPanel1.getHeight()+40;


    //labelling voltages
    label0.setText(st.zero);
    label1.setText(st.v1);
    label2.setText(st.v2);
    label3.setText(st.v3);
    label4.setText(st.v4);
    label5.setText(st.v3);
    label6.setText(st.v4);


    g2.setColor(Color.darkGray);

    for(int i=x; i<width; i=i+80)
    {      
        g2.drawLine(i, y, i, height);          
    }              

    int j = 0;
    for(int i=y; i<height; i=i+80)
    {   
        j++;
        //st.iGain
        g2.setColor(Color.orange);
        if(j==1)
        {
           double k1 = st.iGain * 0.4;
           st.v1 = Double.toString(k1);

           g2.drawString(st.v1, x+5, y+10);
        }            

        if(j==2)
        {               
           double k2 = st.iGain * 0.3;
           st.v2 = Double.toString(k2);

           g2.drawString(st.v2, x+5, y+90);
        }
        g2.setColor(Color.DARK_GRAY);
        g2.drawLine(x, i, width, i); 
       ....         

    } //grid info is not completed yet.

Thanks,

  • 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-05-30T11:57:37+00:00Added an answer on May 30, 2026 at 11:57 am

    Focus isn’t the issue and has nothing to do with your current problem. The solution is to change the properties of the data grid by updating fields it contains via setter methods and calling repaint on the JComponent (perhaps a JPanel, or some other component that derives ultimately from JComponent) held by the data grid. The paintComponent method of this component should use its class fields to update what it draws.

    You almost never paint in the paint method of a JComponent and certainly you don’t want to draw directly into a top-level window. You also probably don’t want to set text of JLabels, JTextFields, or any other JTextComponent. from within paint/paintComponent.

    I can’t see why your code is not working and can only guess that the likely cause of your problem is in code not shown.

    Edit 1:
    Just guessing, but you may have a problem of references. I notice that your listener class creates new DisplayForm and Storage objects:

    DisplayForm dF = new DisplayForm();
    Storage st = new Storage();
    

    There’s a good possibility that these objects are not the ones being displayed, especially if you create these objects elsewhere and display them. Again I’m just guessing since I don’t see the rest of your code, but perhaps you should to pass references for these objects into the DisplayForm via constructor or setter method parameters.

    Edit 2:
    e.g.,

    public void setDisplayForm(DisplayForm dF) {
       this.dF = dF;
    }
    
    // same for Storage
    

    And in the main program:

    public MainDisplayForm() {
        initComponents();
        ButtonListener_IncreaseGain btnListenerIncreaseGain = new ButtonListener_IncreaseGain();
        btnListenerIncreaseGain.setDisplayForm(....);
        btnListenerIncreaseGain.setStorage(....);
        Btn_IncreaseGain.addActionListener(btnListenerIncreaseGain);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made some menu with a slide down submenu. It should work fine
I have made some menu items, and the items popup when I click menu
I have a little problem, I just made a menu with some asp:hyperlink structured
Just started with some basic android development and I made a little menu with
I have menu made with Superfish jquery plugin http://users.tpg.com.au/j_birch/plugins/superfish But i have some problems
I have made a diary where I have a menu that echoes out every
I'm working on a menu (images made with indesign, not yet html): Some menu
I made some changes to an existing application that was previously just straight HTML
I made some changes to an open source project without taking time to create
I made some code, for understanding the concept/basic of pointer: int a=1; int *b=&a;

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.