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

  • Home
  • SEARCH
  • 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 6362877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:57:52+00:00 2026-05-24T23:57:52+00:00

The current project in wherein I’m working creates a log file using the log4j

  • 0

The current project in wherein I’m working creates a log file using the log4j library and also must have the functionality “showLog” which create a frame where the log can be viewed. Moreover, this frame has to refresh when the log file is modified (appending a new log message).

Well, I have done all except the refresh action, and this is the question, how can I do the dynamically refresh?

Here fragments of my code, I put only the relevant lines:

  • Interface Action: runs the event actions

    public interface Action {
        public void executer();
    }
    

  • Class CadreTexte: Creates and manages the frame wherein the log file is showed

    public class CadreTexte extends JFrame {
        private JTextPane log;
        public CadreTexte(String titre, File texte) {
            super(titre);
            if (texte.exists() && texte.canRead()) {
                this.texte = texte;
            }
            else {
                throw new ExceptionGenerateurs("NE_FILE"); //Own exception
            }
            initializeFrame();
    log= new JTextPane(); log.setEditable(false); java.net.URL urlFichier = null; try { urlFichier = texte.toURI().toURL(); } catch (MalformedURLException e1) { throw new ExceptionGenerateurs("Fichier de texte non montrable"); } try { log.setPage(urlFichier); } catch (IOException e) { System.out.println(e.getLocalizedMessage()); //CATCH } finally { urlFichier = null; } JScrollPane docSP = setScrollPane(); // bars as needed, contains JTextPane getContentPane().setLayout(new BorderLayout()); getContentPane().add(docSP,BorderLayout.CENTER); } }

  • Class Vue: main frame. It has a list of Action objects which are stored into a HashMap. The actions are accessible throught a menu. Due to this class is very large, I put only the most important lines:

    1. ActionPerformed Function:

      public void actionPerformed(ActionEvent e) {
      JComponent composant;
      Action handler;
      composant = (JComponent) e.getSource();
      String idEvenement = composant.getName();
      modele.log(Modele.LOG_DEBUG, String.format("Événement. ID: %s",idEvenement));
      handler = ACTIONS_MAP.get(idEvenement);
      if (handler == null) {
          modele.log(Modele.LOG_ERROR, "Action non identifiée");
      } else {
          handler.executer();
          modele.log(Modele.LOG_DEBUG, "Fin action");
      }
      }
      

    2. Action visualiserLog:

      Action visualiserLog = new Action() {
      public void executer() {
          if (cadreLog == null) {
              cadreLog = new CadreTexte("Fichier du log", model.getLogFile());
              visuLog = true;
          }
          else {
              visuLog = !visuLog;
          }
          cadreLog.visualiser(visuLog);
      }
      };
      

Finally, the MenuItem which activates the visualiserLog Action it’s a JCheckBoxMenuItem

I hope you can help me after understand this large question. If someone needs more information, ask for it!

Regards!

NOTE: I’d be very grateful if someone can edit and give correct format to the question, I have been fighting with the editor and it wins me =(

  • 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-24T23:57:53+00:00Added an answer on May 24, 2026 at 11:57 pm

    I’m not sure that automatic refreshes are a good idea: log files are normally very frequently modified, and can quickly become quite long, so you have a risk of constantly rereading a long file to update the area, and this area, being constantly updated, could become hard to read.

    If you really want to do that, I think the only solution is to read the file first and store its length or modification date, and then start a thread which, every N seconds, compares the length or modification date with the one stored in memory.If it has changed, re-read the file and update the text area and the length or modification date.

    Be careful not to update the text area from the polling thread, but from the event dispatch thread. Use SwingUtilities.invokeLater to do it.

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

Sidebar

Related Questions

My current project is using a metadata file to set properties without having to
in my current project I'm using code first approach. I have a type called
My current project involves deploying an upgraded .exe file that runs as a Windows
On my current project, we've been using Struts 1 for the last few years,
In my current project we are testing our ASP.NET GUI using WatiN and Mbunit
For a current project I am working I need to return an aggregate report
In my current project, I'm producing weekly releases. I've been using the technique described
Current Project Setup I've been working on a web-based chat, similar to Facebook chat.
In my current project i have to transfer data EVERY DAY from MS Access
My current project has us using TreeSet and TreeMap in Java, with an input

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.