Solved

Scrollpane question

Posted on 2004-08-05
10
428 Views
Last Modified: 2010-03-31
trying to add a scrollpane to this applet so incase results gets too long, tried to add a textarea which seems to have scollpane but the textarea wont let me add a label to it can someone help      

        public void init() {
                                     panel = new Panel(new FlowLayout());
                           panel.add( searchTextField);
                 panel.add( searchButton );
                 //textArea = new TextArea(25, 65);
                // panel2.add(textArea);
                                     add(panel);
                                     add(panel2);                  
            }


public void displayResults()
            {
            try{                  
             while (rs.next())
            {
               Title = rs.getString("Title");
                  Url = rs.getString("Url");
              label1 = new Label(i+ " "  + new String(Title));
                label2 = new Label(new String(Url));
                          textArea.add(label1);
                                textArea.add(label2);
                                panel2.add(label1);
                          panel2.add(label2);
                label1.addMouseListener(new PageOpener(Url));
            validate();
            repaint();
            }  
                  
            }catch (Exception e){System.out.println(e.getMessage());}
            
            }
0
Comment
Question by:HomerrSimpson
[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
  • 2
  • 2
  • +2
10 Comments
 
LVL 15

Expert Comment

by:Javatm
ID: 11731398
This should solve it :

JTextArea t1 = new JTextArea("Sample Text . . .");
JPanel p1 = new JPanel();
p1.add(new JScrollPane(t1);

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

Hope that helps . . .
Javatm
0
 
LVL 92

Expert Comment

by:objects
ID: 11731501
Add your label to a panel (that you want scrolled). And then add that panel to your scrollpane.
0
 
LVL 15

Expert Comment

by:Javatm
ID: 11731573
Can you be more specific if our answers are limited that is because your
question is quite hard to understand, thanks.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Expert Comment

by:rimmer0007
ID: 11731593
you mean like that this objects


ScrollPane pane = new ScrollPane();

public displayREsults(){
.......
panel2.add(label1);
 panel2.add(label2);
 panel2.add(pane);
......
}

nothing gets displayed. get a java.lang null pointer exception when trying to display results
also tried


public displayREsults(){
......
panel2.add(label1);
 panel2.add(label2);
 panel2.add(pane);
add.(panel2);
.....
}
0
 
LVL 92

Accepted Solution

by:
objects earned 80 total points
ID: 11731631
try:

panel2.add(label1);
panel2.add(label2);
pane.add(panel2);
add(pane);
0
 

Author Comment

by:HomerrSimpson
ID: 11735034
tried it Objects it works now

how do i display the labels one below each as currently the labels are displayed side to side inside the scrollpane

i tried doing this but doesnt work

      label1 = new Label(i+ " "  + new String(Title) + "\n" );
                label2 = new Label(new String(Url) +"\n" );
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 20 total points
ID: 11735719
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 11735729
You can also set a null layout and use the setBounds () method to set the location/ size of the labels.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 80 total points
ID: 11740581
> how do i display the labels one below each as currently the labels are displayed side to side inside the scrollpane

you'll need to change the layout manager.
try a GridLayout

panel2.setLayout(new GridLayout(0, 1));
0
 
LVL 92

Expert Comment

by:objects
ID: 11758552
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

734 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