File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes JPanel on JScrollBar possible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JPanel on JScrollBar possible?" Watch "JPanel on JScrollBar possible?" New topic
Author

JPanel on JScrollBar possible?

Sandeep Mukherji
Ranch Hand

Joined: Mar 23, 2008
Posts: 46
/*
I made two JPanel panel and p. Then pasted labels, tesxtFields and button
Then pasted that panel p to panel and put it on the scrollBar. scrollBar is on the JFrame in turn. The size of the scrollBar is set lesser than the panel. Still the scrollbars are not working. I can not see the whole form.
Can somebody help please.
*/
package exp;
import javax.swing.*;
import java.awt.*;
/**
* @author Sandeep Mukherji
*
*/
public class Invoice_Generate extends JFrame{
JScrollPane scrollPane;
JPanel panel,p;
JLabel label;
JTextField textField;
JButton button;
Invoice_Generate(){
super("Name");
setVisible(true);
setSize(400,200);
setLayout(null);
panel = new JPanel();
panel.setSize(300,100);
panel.setLayout(null);
//panel.setVisible(true);
panel.setBackground(Color.YELLOW);
label = new JLabel("Label");
textField = new JTextField();
button = new JButton("add");
label.setBounds(0,0,100,30);
textField.setBounds(120,0,100,30);
button.setBounds(0,50,80,30);
panel.add(label);
panel.add(textField);
panel.add(button);
p = new JPanel();
p.setVisible(true);
p.setSize(500,500);
p.setLayout(new BorderLayout());
p.add(panel, BorderLayout.CENTER);
scrollPane = new JScrollPane(p);
//scrollPane.add(panel);
scrollPane.setSize(300,100);
//scrollPane.setLayout(new ScrollPaneLayout());
scrollPane.setVerticalScrollBarPolicy(scrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(scrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
//scrollPane.se
scrollPane.setVisible(true);
add(scrollPane);
}
public static void main(String a[]){
new Invoice_Generate();
}
}
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Why don't you try setting the size of the panel as below:
Set your frame to fix the size and now you may get vertical bar.
Sandeep Mukherji
Ranch Hand

Joined: Mar 23, 2008
Posts: 46
Thanks a lot Gopu. It is working now.
Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
I could managed to get the vertical bar for the scrollpane through setting the setPreferredSize for the panel. Is tehre any way to get the horizontal bar?
Sandeep Mukherji
Ranch Hand

Joined: Mar 23, 2008
Posts: 46
yes, you can use

This will fix the size of the columns and you will get the horizontal scrollbar.
I hope this will help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPanel on JScrollBar possible?