• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

how to add a scrollpane...

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi huys
did somebody know how to add a scrollPane to JFrame ???
Thanx
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try it? Just declare your frame and scrollpane references and just add as follows...
yourFrame.add(yourPane)

Bosun
 
vikas de
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried this...
ScrollPane js=new ScrollPane();
studentFrame.getContentPane().add(js);
but it doesnt run...it doesnt display any scrollpane...
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vikas,
You need to place something into the ScrollPane. The ScrollPane by itself will never be visible. Try the following:

Regards,
Manfred.
 
vikas de
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the scrollpane is know visible but only from left to right...
is it possible to set the scrollpane that it will be displayed from top to down....???
 
vikas de
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to add a vertical scrollpane...did somebody know how this is possible...in my code i have add a scrollpane but it displays only horizontal...and i want it vertical
please see the code...
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class SwingWithMe
{
public static void main(String args[])
{
JTextField[] myTextField=new JTextField[30];
JPanel myPanel=new JPanel();
JFrame myFrame=new JFrame("Test");
JScrollPane myPane= new JScrollPane();
for(int i=0;i<30;i++)
{
myTextField[i]=new JTextField(10);
myPanel.add(myTextField[i]);
}
myPane=new JScrollPane(myPanel);
myFrame.getContentPane().add(myPane,BorderLayout.CENTER);
myFrame.setResizable(false);
myFrame.setLocation(0,100);
myFrame.setSize(1030,500);
myFrame.setVisible(true);
}
}
please help as soon as possible...
vikas

[This message has been edited by vikas de (edited March 30, 2001).]
 
vikas de
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Come on Guys....Please help its urgent...
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main problem with your current program is that myPanel has a default layout manager of FlowLayout. This means when you add things to it, they get added horizontally until you exceed the container's maximum width - only then will components be added to the next row instead. Since myPanel is inside a scroll pane, it has no maximum width - it can keep growing indefinitely. So there's never any reason for the LayoutManager to start a new line.
Why do you create two JScrollPanes? It looks like the first is never used - you should clean up your code to avoid needless confusion. I found your code difficult to follow - names like "myPane" and "myPanel" tell me nothing about the intended relationship between the components. I gave the components slightly more descriptive names in the code below. Note that I also changed the frame size and number of text fields to ensure that the scroll pane would actually be needed both horizontally and vertically. The scroll bar will only appear if the component inside the scroll pane is too large for the scroll pane in that direction (horizontal or vertical).
<code><pre>
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class SwingWithMe
{
public static void main(String args[])
{
JTextField[] textFields = new JTextField[100];
// start with one plain inner panel to hold all the textfields
JPanel innerPanel = new JPanel();
innerPanel.setLayout(new GridLayout(10, 10));
for (int i = 0; i < textFields.length; i++)
{
textFields[i] = new JTextField(10);
innerPanel.add(textFields[i]);
}
// put the inner panel into a scroll pane
JScrollPane scrollPane = new JScrollPane(innerPanel);
// construct an outer frame to hold the scroll pane
JFrame outerFrame = new JFrame("Test");
outerFrame.getContentPane().add(scrollPane);
outerFrame.setResizable(false);
outerFrame.setLocation(0, 100);
outerFrame.setSize(300, 200);
outerFrame.setVisible(true);
System.out.println("innerPanel size is " + innerPanel.getSize());
System.out.println("scrollPane size is " + scrollPane.getSize());
}
}
</pre></code>

[This message has been edited by Jim Yingst (edited April 01, 2001).]
 
I can't beleive you just said that. Now I need to calm down with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic