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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:16:54+00:00 2026-06-04T20:16:54+00:00

I have developed a task manager for Linux in Java. The output as of

  • 0

I have developed a task manager for Linux in Java. The output as of now is displayed in the console whereas a tabbed window appears separately (this was done using Java Swing).
Now I want the output from the console to be displayed in the tabbed window.

How do I do it?

There are classes that I’ve used. One for the task manager functionality and the other for GUI. I’ve pasted below the coding.

**TabbedPaneDemo1.java**

package components;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.Writer;
import java.util.Iterator;
import java.util.List;


/*
 * TabbedPaneDemo.java requires one additional file:
 *   images/middle.gif.
 */

import javax.swing.JTabbedPane;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.JTextField;
import javax.swing.JTextArea;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.TextArea;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

public class TabbedPaneDemo1
{

public static void main(String args[]) throws Exception
{
    try
    {   
        TextArea textarea = new TextArea();
        TabbedPaneDemo obj = new TabbedPaneDemo();
        obj.fn();
        String line;
        String result = "";
        FileOutputStream out;
        //FileOutputStream out; // declare a file output object
        PrintStream p;
        Process p1 = Runtime.getRuntime().exec("tasklist.exe");
        out = new FileOutputStream("myfile.txt");//write to a file//
        p = new PrintStream( out );
        BufferedReader input = new BufferedReader(new InputStreamReader(p1.getInputStream()));//read form a file//
        while ((line = input.readLine()) != null)
        {
            System.out.println(line);
            //textarea.append(line + "\n");
            result += line+"\n";
            p.println (line);
            //textarea.setVisible(true);    
        }
        //msgBox(result);
        p.close();
        input.close();   
    }
    catch(Exception e)
    {

    }
}
    public static void msgBox(String msg) {
    javax.swing.JOptionPane.showConfirmDialog((java.awt.Component)
    null, msg, "WindowsUtils",
    javax.swing.JOptionPane.DEFAULT_OPTION);
    }
}

**TabbedPaneDemo.java**

package components;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import javax.swing.JTabbedPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;

public class TabbedPaneDemo extends JPanel {
Integer i;
public TabbedPaneDemo() {
    super(new GridLayout(1, 1));

    JTabbedPane tabbedPane = new JTabbedPane();
    ImageIcon icon = createImageIcon("images");


    JComponent panel1 = makeTextPanel("tasklist");
    tabbedPane.addTab("tasks", icon, panel1,
            "ta");
    tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);

    JComponent panel2 = makeTextPanel("windows");
    tabbedPane.addTab("wins", icon, panel2,
            "wi");
    tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);


    add(tabbedPane);`enter code here`
        tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);    
    }
    protected JComponent makeTextPanel(String text)
    {
        JPanel panel = new JPanel(false);
        JLabel filler = new JLabel(text);
        filler.setHorizontalAlignment(JLabel.CENTER);
        panel.setLayout(new GridLayout(1, 1));
        panel.add(filler);
        return panel;
    }
    protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = TabbedPaneDemo.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
    private static void createAndShowGUI() {
        JFrame frame = new JFrame("TabbedPaneDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(new TabbedPaneDemo(), BorderLayout.CENTER);
        frame.pack();
        frame.setVisible(true);
    }
    public static void fn() {
        SwingUtilities.invokeLater(new Runnable() {
            public void run()
            {
        UIManager.put("swing.boldMetal", Boolean.FALSE);
        createAndShowGUI();
            }
        });
    }
}
  • 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-04T20:16:56+00:00Added an answer on June 4, 2026 at 8:16 pm

    This is a very naive implementation of it.

    package test.t100.t001;
    
    import java.awt.*;
    import java.awt.event.KeyEvent;
    import java.io.BufferedReader;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintStream;
    
    import javax.swing.*;
    
    public class TabbedPaneDemo extends JPanel {
    
        private static final long serialVersionUID = 1L;
        Integer i;
    
        JTextArea output = new JTextArea();
    
        public static void main(String args[]) 
        {
            SwingUtilities.invokeLater(new Runnable() {
                public void run()
                {
                    JFrame frame = new JFrame("TabbedPaneDemo");
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.add(new TabbedPaneDemo(), BorderLayout.CENTER);
                    frame.pack();
                    frame.setVisible(true);
                }
            });
        }
    
        private String getDetails() throws IOException {
            //fn();
            String line;
            String result = "";
            PrintStream p;
            Process p1 = Runtime.getRuntime().exec("tasklist.exe");
            // read from a process
            BufferedReader input = new BufferedReader(
                    new InputStreamReader(p1.getInputStream()));
            while ((line = input.readLine()) != null)
            {
                //System.out.println(line);
                output.append(line + "\n");
                result += line+"\n";
                //p.println (line);
                //textarea.setVisible(true);    
            }
            //msgBox(result);
            //p.close();
            input.close();   
    
            return result;
        }
    
        public TabbedPaneDemo() {
            super(new GridLayout(1, 1));
    
            JTabbedPane tabbedPane = new JTabbedPane();
            ImageIcon icon = createImageIcon("images");
    
    
            JComponent panel1 = makeTextPanel("tasklist");
            tabbedPane.addTab("tasks", icon, panel1,
                    "ta");
            // add it to something!
            panel1.add(new JScrollPane(output));
            tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
    
            JComponent panel2 = makeTextPanel("windows");
            tabbedPane.addTab("wins", icon, panel2,
                    "wi");
            tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
    
    
            add(tabbedPane);//`enter code here`
            tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    
            try {
                String s = getDetails();
                output.setText(s);
            } catch(IOException e) {
                e.printStackTrace();
            }
        }
    
    
        public static void msgBox(String msg) {
            javax.swing.JOptionPane.showConfirmDialog((java.awt.Component)
                    null, msg, "WindowsUtils",
                    javax.swing.JOptionPane.DEFAULT_OPTION);
        }
    
    
        protected JComponent makeTextPanel(String text)
        {
            JPanel panel = new JPanel(false);
            JLabel filler = new JLabel(text);
            filler.setHorizontalAlignment(JLabel.CENTER);
            panel.setLayout(new GridLayout(1, 1));
            panel.add(filler);
            return panel;
        }
    
        protected static ImageIcon createImageIcon(String path) {
            java.net.URL imgURL = TabbedPaneDemo.class.getResource(path);
            if (imgURL != null) {
                return new ImageIcon(imgURL);
            } else {
                System.err.println("Couldn't find file: " + path);
                return null;
            }
        }
    }
    

    Other notes:

    1. For better help sooner, post an SSCCE. Especially don’t include unnecessary images.
    2. Use a JTable for this type of data.
    3. The code dumps the text area in a tabbed pane that apparently has a GridLayout – BNI
    4. Don’t mix Swing & AWT components without good reason.
    5. As already mentioned, use a SwingWorker for getting the data.

    Update

    ..but the output from the console doesn’t appear.

    Uh-huh. Let’s think about

    I have developed a task manager for Linux in Java

    ..combined with..

    Process p1 = Runtime.getRuntime().exec("tasklist.exe");
    

    Now, correct me if I misunderstand something, but AFIAU Linux has no EXEs.

    I’m guessing the code fails on Linux, and since the err stream of the process is being ignored, you are not being told why. Here is a screen-shot of the code shown above, as it appears on Windows 7.

    Working output in tabbed pane

    Now, if the data had been hard-coded, you might be seeing something like above. Which answers the stated question of “(How to) Display output in a tabbed window”, right?

    More info. on the new problem you are seeing is to be had by implementing all the recommendations of When Runtime.exec() won’t. If you implement all the suggestions & still cannot figure the problem, I suggest you ask a new question.

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

Sidebar

Related Questions

I have developed a task manager for linux in java. The output as of
I have developed an SSIS custom task component. It uses a connection manager of
Task at hand — I have three versions of some code, developed by different
I have developed a window application in VS2005 using C#. I need to integrate
I have developed two custom task pane addins to be used in Excel 2007.
I have developed one window application in C# where i am creating one thread
I have developed one web application for monitoring azure application (Webrole) by console(EXE) application
i have developed a complete project for iPad and now i want the same
I have a task assigned to me but I am not a project manager.
I have been given the unenviable task of cleaning up after a developer who

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.