?
Solved

Scrollpane question

Posted on 2004-08-05
10
Medium Priority
?
434 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 320 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 80 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 320 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month16 days, 9 hours left to enroll

862 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