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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:30:44+00:00 2026-06-05T23:30:44+00:00

I wanted to make a JOptionPane.showOptionDialog with some JTextArea and JLabel . The problem

  • 0

I wanted to make a JOptionPane.showOptionDialog with some JTextArea and JLabel.
The problem was that the dialog was too small and i didn’t find any solutions, so i just decided to put my content in a JScrollPane.

I saw that i must put all my JTextArea and my JLabel in a JPanel because adding them in the JScrollPane in a row doesn’t allow me to put the viewport correctly.

The final problem is that my JTextArea are wrapping words correctly but when i have words of 2 or 3 letters lenght, they are hide by the scrollbar.

SSCCE :

public class myTest extends JFrame
{
        public static void main(String[] args)
        {
            new myTest();
        }
        public myTest()
        {
            String myLongString="Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?";
            String aLittleString="I am a poor little string which is placed at the bottom of a JOptionPane.";
            String[] options = {"OK","NO"}; 

            JLabel titre1 = new JLabel("Title"); 
            JLabel titre2 = new JLabel("Title 2");

            Map<TextAttribute,Integer> attributs = new HashMap<TextAttribute, Integer>();
            attributs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
            Font police = new Font("Serif", Font.BOLD, 12).deriveFont(attributs); 

            titre1.setFont(police);
            titre2.setFont(police);

            JTextArea text3 = new JTextArea(myLongString,5,75); 
            text3.setLineWrap(true);
            text3.setWrapStyleWord(true);
            text3.setEditable(false);
            Color back = this.getBackground();
            text3.setBackground(back);
            JTextArea text = new JTextArea(myLongString,5,75); 
            text.setLineWrap(true);
            text.setWrapStyleWord(true);
            text.setEditable(false);
            text.setBackground(back);

            JTextArea text2 = new JTextArea(aLittleString,5,75); 
            text2.setLineWrap(true);
            text2.setWrapStyleWord(true);
            text2.setEditable(false);
            text2.setBackground(back);
            JPanel bas = new JPanel(new BorderLayout());
            JPanel basbas = new JPanel(new BorderLayout());

            bas.add(titre1,BorderLayout.NORTH);
            bas.add(text,BorderLayout.CENTER);
            basbas.add(titre2,BorderLayout.NORTH);
            basbas.add(text2,BorderLayout.CENTER);
            basbas.add(text3,BorderLayout.SOUTH);
            bas.add(basbas,BorderLayout.SOUTH);

            JScrollPane js = new JScrollPane(bas);
            js.setBorder(null);
            js.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            js.setViewportView(bas);
            JLabel lMessage = new JLabel("A message."); 

            Object[] params = {js,lMessage}; 

            int n = JOptionPane.showOptionDialog(new JFrame(),
                    params,
                    "my dialog", 
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE,
                    null, 
                    options, 
                    options[0]); 

        }
    }

I read several subjects, but they are always speaking about setWrapStyleWord.
I disable the horizontal scrollbar because i don’t want it, in fact i don’t want a scrollbar for 2 letters off-side.

In my opinion the problem is that i construct the scrollbar with a JPanel but i don’t find an other solution.

Any feedback on my post or my english are as well welcome.

  • 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-05T23:30:45+00:00Added an answer on June 5, 2026 at 11:30 pm

    Putting my comment to answer. Please do try to provide one Empty Border to your JPanel to which you are adding JScrollPane, or you can add one EmptyBorder to your JTextArea.

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

Sidebar

Related Questions

If I wanted to make some sort of api so that ANY mobile game
I wanted to make a website that would let users record a small video
I wanted to make a ViewController that had some text editing functionality I wanted
I wanted to make this script work somehow, but i find that after you
I wanted to make some simple file recovery software, where I want to try
I wanted to make an application that will take either the path of the
I wanted to make a function that populates a Grid in WPF with pictures.
I wanted to make a special version of shared_ptr that would perform specific operations
I wanted to make a linked list class ListList that inherits from a class
I wanted to make a simple chart of users that have been created in

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.