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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:55:14+00:00 2026-06-09T23:55:14+00:00

I’m new to GUIs in java. For example, I need to update just 1

  • 0

I’m new to GUIs in java.

For example, I need to update just 1 element (e.g., JLabel). In Tkinter I would use something like root.update() or root.update_idletasks(). I wonder if a similar simple function exists in for applications made with swing. I’ve tried gui_element.SetVisible(false) and gui_element.SetVisible(true) and similar stuff, but not very successfully. I suspect something with javax.swing.Timer should work, but do not know how.

EDIT Here is the code. Please let me know if you find other errors. Thanks

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class sof_sample{

    /**
     * @param args
     */

    private static JFrame frame1 = new JFrame("Fractal Geometry");
    public static JButton quit_button = new JButton("Quit");
    private static JButton run_button = new JButton("Run");
    private static JLabel label1 = new JLabel();
    public static JLabel label_iter = new JLabel(); 
    private static GridLayout layout1 = new GridLayout(2,20);
    private JOptionPane msg1 = new JOptionPane();
    private static int counter;

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        AuxClass1 inst1 = new AuxClass1();
        quit_button.addActionListener(inst1);
        run_button.addActionListener(inst1);
        label1.setText("Iteration");
        label1.setVerticalTextPosition(JLabel.CENTER);
        label1.setHorizontalAlignment(JLabel.CENTER);
        label_iter.setText("0");
        label_iter.setBorder(BorderFactory.createLineBorder(Color.BLACK));      
        label_iter.setVerticalTextPosition(JLabel.CENTER);
        label_iter.setHorizontalAlignment(JLabel.CENTER);

        //add widgets to the frame
        frame1.add(label1);
        frame1.add(label_iter);
        frame1.add(run_button);
        frame1.add(quit_button);

        frame1.setLayout(layout1);
        frame1.setLocationRelativeTo(null);
        //frame1.pack();
        frame1.setSize(250, 75);
        frame1.setVisible(true);

    }

}

class AuxClass1 implements ActionListener{
    sof_sample inst2 = new sof_sample();

    public void actionPerformed(ActionEvent event1){

        if (event1.getSource()==inst2.quit_button){
            System.exit(0);

        }
        else{
            for (int i=0;i<20000;i++){

                inst2.label_iter.setText(Integer.toString(i));

            }
            //msg1.showMessageDialog(frame1, "Not yet!");

        }


    }



}
  • 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-09T23:55:15+00:00Added an answer on June 9, 2026 at 11:55 pm

    Swing is event driven. All components work through the MVC pattern. You don’t need to explicitly repaint it by hiding/showing in order to update it’s representation on the screen.

    You just do yourLabel.setText("your new text") and the new text will appear on the label.

    Keep in mind that most GUI-updates (the setText is an exception) needs to be performed on the EDT, so use SwingUtilities.invokeLater etc if you’re update is triggered by, say, a network message.

    If you do structural changes to the GUI you’ll have to revalidate()/repaint() though.

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

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I have thousands of HTML files to process using Groovy/Java and I need to
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.