[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Adding a scrollbar to a jtextfield

Posted on 2006-12-01
7
Medium Priority
?
932 Views
Last Modified: 2006-12-17
How can i make the JTextField in the following code have a scrollbar?  I've tried results.setCaretPosition(results.getText().length() - 1); after i've filled it, but that
doesnt have any effect.

public class Interface extends JPanel implements ActionListener
      {
            private JLabel component1;
            private JTextField searchString;
            private JLabel component3;
            private JTextField alphaValue;
            private JLabel component5;
            private JTextArea results;
            private JButton component7;
            
            public Interface()
            {
                  //construct components
                              
                  component1 = new JLabel ("Search Term:");
                  searchString = new JTextField (5);
                  component3 = new JLabel ("Alpha Value:");
                  alphaValue = new JTextField (5);
                  component5 = new JLabel ("Results");
                  results = new JTextArea (5, 5);
                  component7 = new JButton ("Search");
                  
                  component7.addActionListener(this);

                  //adjust size and set layout
                  setPreferredSize (new Dimension (747, 480));
                  setLayout (null);

                  //add components
                  
                  add (component1);
                  add (searchString);
                  add (component3);
                  add (alphaValue);
                  add (component5);
                  add (results);
                  add (component7);

                  //set component bounds (only needed by Absolute Positioning)
                  component1.setBounds (5, 5, 80, 25);
                  searchString.setBounds (85, 5, 500, 25);
                  component3.setBounds (611, 5, 73, 25);
                  alphaValue.setBounds (685, 5, 60, 25);
                  component5.setBounds (345, 95, 45, 25);
                  results.setBounds (50, 120, 650, 350);
                  component7.setBounds (265, 45, 100, 25);
                               }
            }
0
Comment
Question by:twibblejaway
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 18052111
Why don't you use JTextArea?
0
 

Author Comment

by:twibblejaway
ID: 18052115
sorry, I meant jtextarea... that is what i'm using
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 18052122
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:twibblejaway
ID: 18052165
No luck.  Anyone else?
0
 
LVL 16

Accepted Solution

by:
suprapto45 earned 1500 total points
ID: 18052215
         //add components
           JScrollPane p = new JScrollPane
          (
               results,
               JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
               JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS
          );
         
          add (component1);
          add (searchString);
          add (component3);
          add (alphaValue);
          add (component5);
          add (p);
          add (component7);

          //set component bounds (only needed by Absolute Positioning)
          component1.setBounds (5, 5, 80, 25);
          searchString.setBounds (85, 5, 500, 25);
          component3.setBounds (611, 5, 73, 25);
          alphaValue.setBounds (685, 5, 60, 25);
          component5.setBounds (345, 95, 45, 25);
          p.setBounds (50, 120, 650, 350);
          component7.setBounds (265, 45, 100, 25);

That works fine on me.
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 18073449
???
0
 

Author Comment

by:twibblejaway
ID: 18156426
Well I dont know why I dont get a scrollbar when I copy and paste that.  
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question