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

  • Home
  • SEARCH
  • 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 8169091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:44:40+00:00 2026-06-06T20:44:40+00:00

i’m new in java and recently started to develop an simple application. For the

  • 0

i’m new in java and recently started to develop an simple application. For the moment i have a problem with JScrollPanne, it’s not able to scroll down (or up) when the text in textarea more than size of area. I have looked to some solutions, but all of them were for FlowLayot (GridLayout and BoxLayout), but not for GroupLayout. Here is the code:

JPanel conent_p = new JPanel();
    conent_p.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));

    JLabel lblItemName = new JLabel("Item name:");
    itemField = new JTextField();
    itemField.setColumns(10);

    JLabel lblMxPrice = new JLabel("Max price:");   
    mpriceField = new JTextField();
    mpriceField.setColumns(10);

    JLabel lblQuantity = new JLabel("Quantity:");
    quanField = new JTextField();
    quanField.setColumns(10);

    JLabel lblDelivery = new JLabel("Delivery:");
    delivField = new JTextField();
    delivField.setColumns(10);

    JLabel lblLogcat = new JLabel("LogCat:");
    final JTextArea txtConsole = new JTextArea();
    txtConsole.setEditable(false);
    txtConsole.setLineWrap(true);
    txtConsole.setWrapStyleWord(true);

    sbrText = new JScrollPane(txtConsole);
    sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    // Now create a new TextAreaOutputStream to write to our JTextArea control and wrap a
    // PrintStream around it to support the println/printf methods.
    PrintStream out = new PrintStream(new TextAreaOutputStream(txtConsole));
    // redirect standard output stream to the TextAreaOutputStream
    System.setOut(out);
    // redirect standard error stream to the TextAreaOutputStream
    System.setErr(out);

    GroupLayout gl_conent_p = new GroupLayout(conent_p);
    gl_conent_p.setHorizontalGroup(
        gl_conent_p.createParallelGroup(Alignment.LEADING)
            .addGroup(gl_conent_p.createSequentialGroup()
                .addContainerGap()
                .addGroup(gl_conent_p.createParallelGroup(Alignment.LEADING)
                    .addComponent(lblMxPrice, Alignment.TRAILING)
                    .addComponent(lblItemName, Alignment.TRAILING)
                    .addComponent(lblLogcat, Alignment.TRAILING))
                .addGap(18)
                .addGroup(gl_conent_p.createParallelGroup(Alignment.LEADING)
                    .addGroup(gl_conent_p.createSequentialGroup()
                        .addGroup(gl_conent_p.createParallelGroup(Alignment.LEADING, false)
                            .addComponent(itemField, GroupLayout.PREFERRED_SIZE, 365, GroupLayout.PREFERRED_SIZE)
                            .addGroup(gl_conent_p.createSequentialGroup()
                                .addComponent(mpriceField, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
                                .addGap(18)
                                .addComponent(lblQuantity)
                                .addPreferredGap(ComponentPlacement.RELATED)
                                .addComponent(quanField, 0, 0, Short.MAX_VALUE)
                                .addGap(18)
                                .addComponent(lblDelivery)
                                .addPreferredGap(ComponentPlacement.RELATED)
                                .addComponent(delivField, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(ComponentPlacement.RELATED)))
                        .addGap(100))
                    .addGroup(gl_conent_p.createSequentialGroup()
                        .addComponent(txtConsole, GroupLayout.PREFERRED_SIZE, 345, GroupLayout.PREFERRED_SIZE)
                        .addComponent(sbrText)
                        .addContainerGap())))
    );
    gl_conent_p.setVerticalGroup(
        gl_conent_p.createParallelGroup(Alignment.LEADING)
            .addGroup(gl_conent_p.createSequentialGroup()
                .addContainerGap()
                .addGroup(gl_conent_p.createParallelGroup(Alignment.BASELINE)
                    .addComponent(lblItemName)
                    .addComponent(itemField, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE))
                .addGap(20)
                .addGroup(gl_conent_p.createParallelGroup(Alignment.LEADING)
                    .addGroup(gl_conent_p.createParallelGroup(Alignment.BASELINE)
                        .addComponent(lblDelivery)
                        .addComponent(delivField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addGroup(gl_conent_p.createParallelGroup(Alignment.BASELINE)
                        .addComponent(lblMxPrice)
                        .addComponent(mpriceField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblQuantity)
                        .addComponent(quanField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                .addGap(55)
                .addGroup(gl_conent_p.createParallelGroup(Alignment.BASELINE)
                    .addComponent(lblLogcat)
                    .addComponent(txtConsole, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
                    .addComponent(sbrText))
                .addContainerGap())
    );
    conent_p.setLayout(gl_conent_p);

    getContentPane().add(conent_p, BorderLayout.NORTH);

    JButton btnBuy = new JButton("Buy");
    btnBuy.addActionListener( new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            try {
                String title = itemField.getText().trim();
                String mprice = mpriceField.getText().trim();
                String quantity = quanField.getText().trim();
                String deliver = delivField.getText().trim();

                Item_CONCEPT item = new Item_CONCEPT();

                item.setName(title);
                item.setDelivery(Integer.parseInt(deliver));
                item.setStartPrice(0);
                item.setMaxPrice(Integer.parseInt(mprice));

                myAgent.existsSeller(item);

                Date date = new Date();
                DateFormat df = new SimpleDateFormat("dd.MM.yy HH:mm");
                System.out.println(df.format(date)+": Buyer orders an item: "+item.getName());

                //Clearing all fields
                itemField.setText("");
                quanField.setText("");
                delivField.setText("");
                //txtConsole.setText("");
                mpriceField.setText("");
            }
            catch (Exception e) {
                JOptionPane.showMessageDialog(BuyerGUI.this, "A field is filled incorrectly. "+e.getMessage()+" is invalid.", "Error", JOptionPane.ERROR_MESSAGE); 
            }
        }
    } );![enter image description here][1]
  • 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-06T20:44:41+00:00Added an answer on June 6, 2026 at 8:44 pm

    The issue you observe comes from two facts:

    • You are adding your content panel to BorderLayout.NORTH
    • You add the text console as well as the scroll pane as separate components

    For the first one: replace

    getContentPane().add(conent_p, BorderLayout.NORTH);
    

    with

    getContentPane().add(conent_p, BorderLayout.CENTER);
    

    and for the second: do not add the txtConsole separately, i.e.

    inside the horizontal group substitute

    .addGroup(gl_conent_p.createSequentialGroup()
      .addComponent(txtConsole, GroupLayout.PREFERRED_SIZE, 345, GroupLayout.PREFERRED_SIZE)
      .addComponent(sbrText).addContainerGap());
    

    with

    .addComponent(sbrText);
    

    and inside the vertical group

    .addGroup(gl_conent_p.createParallelGroup(Alignment.BASELINE)
      .addComponent(lblLogcat)
      .addComponent(txtConsole, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
      .addComponent(sbrText)).addContainerGap()));
    

    with

    .addGroup(gl_conent_p.createParallelGroup(Alignment.BASELINE)
      .addComponent(lblLogcat)
      .addComponent(sbrText)).addContainerGap()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am doing a simple coin flipping experiment for class that involves flipping a
I want use html5's new tag to play a wav file (currently only supported

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.