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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:31:43+00:00 2026-06-14T04:31:43+00:00

I have a problem. Every time, when I add more Symbols(Numbers) to TextArea, it

  • 0

I have a problem. Every time, when I add more Symbols(Numbers) to TextArea, it doesn’t make it scrollable. EDIT: now it works as I want. I only needed to change 2 words. Thanks.

class NumOnly extends KeyAdapter {  

    private String Atlauts = "[^0-9]";  //Allowed Buttons.
    public void keyReleased(KeyEvent e) {   //Key event. What happens when the button is pressed
        String curText = ((JTextComponent) e.getSource()).getText();  //Current text
        curText = curText.replaceAll(Atlauts, ""); 

        ((JTextComponent) e.getSource()).setText(curText);  
    }  
}  

public class kursadarbs{

    public static void main(String[] args) {

        JFrame frame= new JFrame();
        JPanel panel= new JPanel();

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //components
        JLabel label1= new JLabel("Insert first number: ");

        final JTextField textbox1= new JTextField(10);
        textbox1.addKeyListener(new NumOnly());

        JLabel label2= new JLabel("Insert second number: ");

        final JTextField textbox2= new JTextField(10);
        textbox2.addKeyListener(new NumOnly());

        JButton button= new JButton("Calculate");

        final JTextArea textarea= new JTextArea(20,20); //Result is stored in there
        textarea.setEditable(false);
        textarea.setLineWrap(true);
        JScrollPane scroll= new JScrollPane(textarea);
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        textarea.setWrapStyleWord(true);
        textarea.setBorder(new TitledBorder(new EtchedBorder(), "Result"));




        GroupLayout groupLayout = new GroupLayout(panel);
        panel.setLayout(groupLayout);  
        groupLayout.setAutoCreateGaps(true);      
        groupLayout.setAutoCreateContainerGaps(true); 

        GroupLayout.SequentialGroup HorSGroup= groupLayout.createSequentialGroup(); 
        GroupLayout.SequentialGroup VerSGroup= groupLayout.createSequentialGroup(); 

        GroupLayout.ParallelGroup HParallelGroup1= groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING);
        GroupLayout.ParallelGroup HParallelGroup2= groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING);
        GroupLayout.ParallelGroup HParallelGroup3= groupLayout.createParallelGroup(GroupLayout.Alignment.LEADING);

        HParallelGroup1.addComponent(label1); //adding components to the group
        HParallelGroup1.addComponent(label2);
        HParallelGroup2.addComponent(textbox1);
        HParallelGroup2.addComponent(textbox2);
        HParallelGroup2.addComponent(scroll);
        HParallelGroup3.addComponent(button);

        HorSGroup.addGroup(HParallelGroup1);
        HorSGroup.addGroup(HParallelGroup2);
        HorSGroup.addGroup(HParallelGroup3);

        GroupLayout.ParallelGroup VerPGroup1= groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE); //Vertical group
        GroupLayout.ParallelGroup VerPGroup2= groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE);
        GroupLayout.ParallelGroup VerPGroup3= groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE);

        VerPGroup1.addComponent(label1); //adding components to groups
        VerPGroup1.addComponent(textbox1);
        VerPGroup1.addComponent(button);
        VerPGroup2.addComponent(label2);
        VerPGroup2.addComponent(textbox2);
        VerPGroup3.addComponent(scroll);

        VerSGroup.addGroup(VerPGroup1);
        VerSGroup.addGroup(VerPGroup2);
        VerSGroup.addGroup(VerPGroup3);

        groupLayout.setHorizontalGroup(HorSGroup);
        groupLayout.setVerticalGroup(VerSGroup);




        Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (int) (dimension.getWidth()/4);
        int y = (int) (dimension.getHeight()/4);
        frame.setLocation(x, y); //Places the program almost in the middle

        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e)
            {
               //what happens when "calculate" is pressed.
                String first = null, second = null; 
                int first1=0, second1=0;

               first= textbox1.getText();  //getting textbox1 value.
               second= textbox2.getText();

               if(!first.isEmpty() && !second.isEmpty()) //If fields are not empty..
               {
                   first1= Integer.parseInt(first);  //string to integer.
                   second1= Integer.parseInt(second);

                   if(first1<second1){ //Check, if the first number is bigger than second.
                   System.out.println(first1);                 
                   textarea.append(first+"\n");
                   }// Ja ir pareizi 
                   else 
                   {
                       JOptionPane.showMessageDialog(null,"Incorrect data. " );
                   }
               } else 
               {
                   JOptionPane.showMessageDialog(null,"Incorrect data." );
               }
            }
        });


        frame.add(panel); //add the panel
        frame.setSize(500, 500); //program size in pix
        frame.setResizable(false); //putting that the frame can't change size
        frame.setTitle("Kursa darbs");
        frame.setVisible(true);


    }

}

Well, The main problem is the Textarea. As you can see, English is not my native language and I’m a beginner for JFrame.
I have tried everything… Please help.

Thank you Already.

  • 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-14T04:31:44+00:00Added an answer on June 14, 2026 at 4:31 am

    Instead of adding the JTextArea to the groups, add the JScrollPane that contains it!

        //HParallelGroup2.addComponent(textarea);
        HParallelGroup2.addComponent(scroll);
        HParallelGroup3.addComponent(button);
    
        HorSGroup.addGroup(HParallelGroup1); //Horizontālās grupas tiek pievienotas sakārtotajai grupai
        HorSGroup.addGroup(HParallelGroup2);
        HorSGroup.addGroup(HParallelGroup3);
    
        GroupLayout.ParallelGroup VerPGroup1= groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE); //Izveido Vertikālās grupas.
        GroupLayout.ParallelGroup VerPGroup2= groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE);
        GroupLayout.ParallelGroup VerPGroup3= groupLayout.createParallelGroup(GroupLayout.Alignment.BASELINE);
    
        VerPGroup1.addComponent(label1); //Pievieno objektus
        VerPGroup1.addComponent(textbox1);
        VerPGroup1.addComponent(button);
        VerPGroup2.addComponent(label2);
        VerPGroup2.addComponent(textbox2);
        //VerPGroup3.addComponent(textarea);
        VerPGroup3.addComponent(scroll);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using IE8 and webdriver. The problem I have is every time webdriver runs
Every now and then I have a problem with SVN inside eclipse folder gets
I have the following problem: I am trying to add every student in the
I have created an add-in, and every time I try to add it to
I'm a beginner at SQL and have this fairly easy conditional problem: Every installation
I have a problem, storing instances of a viewController object. I want every user
I have a strange problem with in-app billing RESTORE_TRANSACTION command. Every request RESTORE_TRANSACTION request
I have the next problem: TabControl has three TabPages. Every TabPage has its own
I've created a form with code and I have a big problem. Every element
problem is that I have to checkout a different branch for every project. and

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.