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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:36:04+00:00 2026-05-29T20:36:04+00:00

Why does the JTextArea disappear when I switch tabs? I’m running Ubuntu linux, if

  • 0

Why does the JTextArea disappear when I switch tabs? I’m running Ubuntu linux, if that makes a difference at all.

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;

public class LogView extends JPanel {

    private JLabel titleLabel;
    private TextArea orderViewArea;

    public LogView() {

        setLayout(new BorderLayout());
        JPanel mainPanel = new JPanel();

        titleLabel = new JLabel("Logging Information");
        // titleLabel.setPreferredSize(new Dimension(600,50));

        mainPanel.setLayout(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints();

        String[] tempstuff = { "Active", "ALL", "Stuff" };
        JComboBox stageList = new JComboBox(tempstuff);
        stageList.setSelectedIndex(0);

        JComboBox otherList = new JComboBox(tempstuff);
        otherList.setSelectedIndex(0);

        JLabel dateStart = new JLabel("Date Start:   ");
        JLabel dateEnd = new JLabel("Date End:   ");

        JTextField dateStartField = new JTextField(9);
        JTextField dateEndField = new JTextField(9);

        JPanel datePanel = new JPanel(new FlowLayout());
        datePanel.add(dateStart);
        datePanel.add(dateStartField);
        datePanel.add(dateEnd);
        datePanel.add(dateEndField);

        List s = new ArrayList();
        s.add("test1");
        s.add("test2");
        JList orderJList = new JList();
        orderJList.setListData(s.toArray());
        orderJList
                .setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        orderViewArea = new TextArea();
        orderViewArea.setEditable(false);
        orderViewArea.setText("Log stuff:\n Pizza\n Rochester\n stuff");

        constraints.insets = new Insets(10, 10, 10, 10);
        constraints.weighty = 0;
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        mainPanel.add(titleLabel, constraints);

        constraints.weighty = 0;
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        mainPanel.add(stageList, constraints);

        constraints.weighty = 0;
        constraints.gridx = 0;
        constraints.gridy = 2;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        mainPanel.add(datePanel, constraints);


        /*
        constraints.weighty = 0;
        constraints.gridx = 0;
        constraints.gridy = 3;
        constraints.fill = GridBagConstraints.HORIZONTAL;
        mainPanel.add(otherList, constraints);
*/
        constraints.weighty = 1;
        constraints.gridx = 0;
        constraints.gridy = 3;
        constraints.fill = GridBagConstraints.BOTH;
        mainPanel.add(orderJList, constraints);

        //otherList.setVisible(false);
        JScrollPane scroll = new JScrollPane(orderViewArea);
        constraints.gridx = 1;
        constraints.gridy = 2;
        constraints.gridheight = 2;
        constraints.ipady = 5;
        constraints.weighty = 1;
        constraints.weightx = 1;
        constraints.fill = GridBagConstraints.BOTH;
        mainPanel.add(scroll, constraints);

        add(mainPanel);
    }

    public static void main(String args[]){
        JFrame test = new JFrame("TEST");
        JTabbedPane tabs = new JTabbedPane();
        tabs.addTab("test", new LogView());
        tabs.addTab("Test3", new JPanel());
        test.add(tabs);
        test.pack();
        test.setVisible(true);
    }

}
  • 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-29T20:36:05+00:00Added an answer on May 29, 2026 at 8:36 pm

    Don’t mix Swing with AWT components. The ‘start on EDT’ still needs fixing, but try this code and report back.

    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.swing.*;
    
    public class LogView extends JPanel {
    
        private JLabel titleLabel;
        private JTextArea orderViewArea;
    
        public LogView() {
    
            setLayout(new BorderLayout());
            JPanel mainPanel = new JPanel();
    
            titleLabel = new JLabel("Logging Information");
            // titleLabel.setPreferredSize(new Dimension(600,50));
    
            mainPanel.setLayout(new GridBagLayout());
            GridBagConstraints constraints = new GridBagConstraints();
    
            String[] tempstuff = { "Active", "ALL", "Stuff" };
            JComboBox stageList = new JComboBox(tempstuff);
            stageList.setSelectedIndex(0);
    
            JComboBox otherList = new JComboBox(tempstuff);
            otherList.setSelectedIndex(0);
    
            JLabel dateStart = new JLabel("Date Start:   ");
            JLabel dateEnd = new JLabel("Date End:   ");
    
            JTextField dateStartField = new JTextField(9);
            JTextField dateEndField = new JTextField(9);
    
            JPanel datePanel = new JPanel(new FlowLayout());
            datePanel.add(dateStart);
            datePanel.add(dateStartField);
            datePanel.add(dateEnd);
            datePanel.add(dateEndField);
    
            List<String> s = new ArrayList<String>();
            s.add("test1");
            s.add("test2");
            JList orderJList = new JList();
            orderJList.setListData(s.toArray());
            orderJList
                    .setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    
            orderViewArea = new JTextArea();
            orderViewArea.setEditable(false);
            orderViewArea.setText("Log stuff:\n Pizza\n Rochester\n stuff");
    
            constraints.insets = new Insets(10, 10, 10, 10);
            constraints.weighty = 0;
            constraints.gridx = 0;
            constraints.gridy = 0;
            constraints.fill = GridBagConstraints.HORIZONTAL;
            mainPanel.add(titleLabel, constraints);
    
            constraints.weighty = 0;
            constraints.gridx = 0;
            constraints.gridy = 1;
            constraints.fill = GridBagConstraints.HORIZONTAL;
            mainPanel.add(stageList, constraints);
    
            constraints.weighty = 0;
            constraints.gridx = 0;
            constraints.gridy = 2;
            constraints.fill = GridBagConstraints.HORIZONTAL;
            mainPanel.add(datePanel, constraints);
    
    
            /*
            constraints.weighty = 0;
            constraints.gridx = 0;
            constraints.gridy = 3;
            constraints.fill = GridBagConstraints.HORIZONTAL;
            mainPanel.add(otherList, constraints);
    */
            constraints.weighty = 1;
            constraints.gridx = 0;
            constraints.gridy = 3;
            constraints.fill = GridBagConstraints.BOTH;
            mainPanel.add(orderJList, constraints);
    
            //otherList.setVisible(false);
            JScrollPane scroll = new JScrollPane(orderViewArea);
            constraints.gridx = 1;
            constraints.gridy = 2;
            constraints.gridheight = 2;
            constraints.ipady = 5;
            constraints.weighty = 1;
            constraints.weightx = 1;
            constraints.fill = GridBagConstraints.BOTH;
            mainPanel.add(scroll, constraints);
    
            add(mainPanel);
        }
    
        public static void main(String args[]){
            JFrame test = new JFrame("TEST");
            test.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            JTabbedPane tabs = new JTabbedPane();
            tabs.addTab("test", new LogView());
            tabs.addTab("Test3", new JPanel());
            test.add(tabs);
            test.pack();
            test.setVisible(true);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, I am running into an issue using JTextArea and JScrollPane. For some reason
I have been writing a small java application (my first!), that does only a
I have some code that does some initialization (including making a JTextArea object), starts
I'm using java, and I'm trying to make a JTextArea that is non-editable but
In all the examples that I can find that use a JTextArea , the
How does Stackoverflow implement the resizable textarea? Is that something they rolled themselves or
Does the Java language have delegate features, similar to how C# has support for
Does anyone have any recommendations of tools that can be of assistance with moving
Does anyone use have a good regex library that they like to use? Most
I've managed to make a typewriter class that does what I want it to

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.