Solved

Scrollpane question

Posted on 2004-08-05
10
429 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

728 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