Solved

Scrollpane question

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

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 106
MySQL  on Tomcat 8 71
hibernate example using maven 12 59
Tomcat: Unable to run tomcat service. 2 24
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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

821 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