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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:32:51+00:00 2026-06-12T07:32:51+00:00

I’m having an issue with next JTabbedPanes that has me stumped. I’ve isolated the

  • 0

I’m having an issue with next JTabbedPanes that has me stumped. I’ve isolated the issue into a short demo application (based on the oracle tabbed pane tutorial):

package main.java;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class TabbedPaneDemo extends JPanel {

public static JTabbedPane topTabs = new JTabbedPane();

public TabbedPaneDemo() {
    super(new BorderLayout());

    topTabs.setPreferredSize(new Dimension(400, 200));

    topTabs.add(makeReadoutPanel("\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15"));

    add(topTabs);
}

private static JTabbedPane makeReadoutPanel(String text) {
  // Create tabbed pane
  JTabbedPane tabs = new JTabbedPane();
  tabs.setName("Tabs");

  // Create text field
  JTextArea textArea = new JTextArea(text);
  textArea.setEditable(false);
  textArea.setFont(new Font("Monospaced", Font.PLAIN, 14));

  // Create first panel for text field
  JPanel textPanel = new JPanel();
  textPanel.setLayout(new BorderLayout());
  textPanel.setName("Text Panel");
  textPanel.add(textArea, BorderLayout.CENTER);

  // Add text field panel to tabs
  tabs.add(textPanel);

  return tabs;
}

private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("TabbedPaneDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Add content to the window.
    frame.add(new TabbedPaneDemo(), BorderLayout.CENTER);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

public static void main(String[] args) {
    //Schedule a job for the event dispatch thread:
    //creating and showing this application's GUI.
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          //Turn off metal's use of bold fonts
          UIManager.put("swing.boldMetal", Boolean.FALSE);
          createAndShowGUI();
        }
    });
}
}

When this is run, the JTextArea gets cut off, without a scroll bar, rather than fitting vertically to the panel. Shouldn’t the BorderLayout in the textPanel make the text area size to the tabs? This only happens with nested tabs: if I use only a single level of tabs the text area fits properly.

  • 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-12T07:32:52+00:00Added an answer on June 12, 2026 at 7:32 am

    You need to add the JTextArea to the viewport of a JScrollBar and then add that to the component held by the JTabbedPane.

    JPanel textPanel = new JPanel();
    textPanel.setLayout(new BorderLayout());
    textPanel.setName("Text Panel");
    
    // **** note change:
    textPanel.add(new JScrollPane(textArea), BorderLayout.CENTER);
    

    Note that there are two common ways to add the component (JTextArea here) the viewport. One is to pass it into the JSrollPane’s constructor as noted above, and another is to call setViewportView(...) on an already created JScrollPane passing in the component into the method’s parameter. Whatever you do, do not pass the JTextArea into an already created JScrollPane with its add(...) method as you’ll remove the scrollpane’s veiwport, and this will prevent it from working properly.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have a small JavaScript validation script that validates inputs based on Regex. I
I want to count how many characters a certain string has in PHP, but
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.