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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:47:27+00:00 2026-05-30T09:47:27+00:00

I have a JTextArea in a JPanel that I would like to use a

  • 0

I have a JTextArea in a JPanel that I would like to use a JScrollPane with. I am using GridBagLayout. When I run it it seems the frame makes room for the JScrollPane but it does not show up, any help would be appreciated. I have been trying to study the docs.oracle page and here Add JScrollPane to a JPanel but for some reason it refuses to show up.

final JTextArea test= new JTextArea(5,30);
test.setLineWrap(true);
test.setWrapStyleWord(true);
test.setEditable(false);
JScrollPane spane = new JScrollPane(test);
spane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);        

JFrame frame = new JFrame ();

frame.setSize(800, 250);
frame.setTitle("test1");
frame.setLocation(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.getContentPane().add(spane);

GridBagConstraints k = new GridBagConstraints();
k.gridx = 4;
k.gridy = 5;
a.setConstraints(spane,k);
container.add(spane);
  • 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-30T09:47:29+00:00Added an answer on May 30, 2026 at 9:47 am

    your variable container is JPanel? I think you forget to call the add() method. But below is my suggestion code.

    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.ScrollPaneConstants;
    import javax.swing.SwingUtilities;
    
    public class MyScrollPane extends JPanel
    {
    
        public MyScrollPane()
        {   
            GridBagConstraints k = new GridBagConstraints();
            k.gridx = 4;
            k.gridy = 5;
    
    
    
            final JTextArea test= new JTextArea(5, 30);
            test.setLineWrap(true);
            test.setWrapStyleWord(true);
            test.setEditable(false);
    
            JScrollPane spane = new JScrollPane(test);
            spane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    
            GridBagLayout gbl = new GridBagLayout();
            gbl.setConstraints(spane,k);
    
            JPanel panel = new JPanel(gbl);     
            panel.add(spane);
            add(panel);
    
        }
    
    
        private static void createAndShowGUI()
        {
    
    
            JFrame frame = new JFrame();
            frame.setSize(800, 250);
            frame.setTitle("test1");
            frame.setLocation(300, 300);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setResizable(false);
            frame.getContentPane().add(new MyScrollPane());
    
    
    
            frame.setVisible(true);
        }
    
        public static void main(String[] args)
        {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run()
                {
                    createAndShowGUI();             
                }
            });
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have embedded a JTextArea on a JScrollPane and am using that JTextArea for
I have JTextArea working with scroll bars provided by JScrollPane. Following that pattern I
I have a JTable that I would like to display a fancy tooltip (basically
I have created JTextpane and inserted components inside textpane (components like Jtextarea). (vertical scrollbar
I have a JTextArea in a JPanel. How can I have the JTextArea fill
I have JScrollPane with JTextArea inside it and I am trying to set the
So here's the deal: I've got a JPanel and a JTextArea inside that one.
I would like to have 6 checkboxes, and do some stuff after a botton
I have a JComboBox named jComboBox18 and a JTextArea jTextArea11. Now I want that
I have developed an editor using java Jpanel, component, etc....I have 2 text areas

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.