Solved

Scrollpane question

Posted on 2004-08-05
10
424 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
 

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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:mayankeagle
mayankeagle earned 20 total points
ID: 11735719
0
 
LVL 30

Expert Comment

by:mayankeagle
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now