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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:07:51+00:00 2026-06-03T22:07:51+00:00

I have this class as an example of my problem. The scrollpane doesn’t scroll,

  • 0

I have this class as an example of my problem. The scrollpane doesn’t scroll, and I can’t see a good reason why:

    import java.awt.Dimension;

import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;


public class DoesNotScroll{ 

    public static void main(String[] args){
        String str = "this\n\nshould\n\n\n\nscroll\n\n\nthis is the bottom";
        message("test", str, JOptionPane.INFORMATION_MESSAGE);
    }

    public final static void message(String title, String message, int messageType){
        JTextArea messageArea = new JTextArea();
        messageArea.setMinimumSize(new Dimension(300, 100));
        messageArea.setMaximumSize(new Dimension(300, 100));
        messageArea.setPreferredSize(new Dimension(300, 100));
        messageArea.setEditable(false);
        JScrollPane scroller = new JScrollPane(messageArea);
        scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        scroller.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        messageArea.setText(message);
        messageArea.revalidate();
        messageArea.repaint();
        JOptionPane.showMessageDialog(null, scroller, title, messageType);
    }
}

Any help is appreciated,

-C

  • 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-03T22:07:53+00:00Added an answer on June 3, 2026 at 10:07 pm

    The problem with my setup here was that I was calling messageArea.setPreferredSize() instead of scroller.setPreferredSize(). Once i took the sizing method calls off of messageArea and added them to scroller, the scrollbars were visible. I am not sure why this works the way it does, but if I figure it out, I’ll update this answer. If anyone else knows, a comment here would be appreciated.

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

Sidebar

Related Questions

I have a problem implementing this example in java, tableFilterDemo is a class that
Suppose I have this code: class Example(object): def the_example(self): itsProblem = "problem" theExample =
For example I have this: class A{ private int mine = 0; //Some field...
I have this example: public class Inheritance { public static class Animal { public
For example I have this in a class: private $messages = array( 'name'=> '<aa_f>name',
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
I have seen example code like this before class C { C(); ~C(); foo(T1,
Say I have a class ObjectA (a view controller for example), that does this
I have a class that contains a List<> of objects. For this example I
I have this weird problem as to how to name objects of a class.

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.