troubleshooting Question

JFrame's TabbedPane has component sizing problems

Avatar of James Hancock
James HancockFlag for United States of America asked on
7 Comments1 Solution328 ViewsLast Modified:
I have a tabbed pane which must have 4 tabs.
One of the tabs refuses to size a text area properly.

Code below...
The design tab can't hold the big text area. One tab is okay with a text field.
How do I embiggen the panes, tabs and components?

Must the Tab pane itself be bigger?


import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.KeyEvent;

public class controlFrame extends JPanel {

	JComponent[] panels;
	JTextField textfield;
	JTextArea  designTextArea;

    public controlFrame() {
        super(new FlowLayout(FlowLayout.LEFT));
        this.setSize(2200, 1100);
        JTabbedPane tabbedPane = new JTabbedPane();
        tabbedPane.setSize(800, 700);
        ImageIcon icon=null;
        panels = new JComponent[5];
         panels[0] = makeTextPanel("Design");
        tabbedPane.addTab("Design", icon, panels[0],
        tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
        textfield = new JTextField();
        designTextArea = new JTextArea();
        textfield.setSize(100, 40);
        designTextArea.setSize(1000, 600);
        panels[1]  = makeTextPanel("Panel #1");
        tabbedPane.addTab("tab 1", icon, panels[1],
        tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
        panels[2]  = makeTextPanel("Panel #2");
        tabbedPane.addTab("tab 2", icon, panels[2],
                "Still does nothing");
        tabbedPane.setMnemonicAt(2, KeyEvent.VK_3);
        panels[3] = makeTextPanel(
                "tab 3");
        panels[3].setPreferredSize(new Dimension(410, 50));
        tabbedPane.addTab("tab 3", icon, panels[3],
                "Does nothing at all");
        tabbedPane.setMnemonicAt(3, KeyEvent.VK_4);
        //Add the tabbed pane to this panel.
        //The following line enables to use scrolling tabs.
    protected JComponent makeTextPanel(String text) {
        JPanel panel = new JPanel(false);
        JLabel filler = new JLabel(text);
        panel.setLayout(new GridLayout(1, 1));
        return panel;
    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path) { imgURL = controlFrame.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from
     * the event dispatch thread.
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("TabbedPaneDemo");
        frame.setSize(1500, 1500);
        //Add content to the window.
        frame.add(new controlFrame(), BorderLayout.CENTER);
        //Display the window.
    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);
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros