How to use JScrollPane inside JTabbedPane

i need to use JScrollPane to view the all area in JPanel that is added to JTabbedPane.

JScrollPane js=new JScrollPane(panel,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

the panel is set to null layout and using setBounds i am adding the components to panel.Ths added components are some other JPanel.
when i use this code,i am not able view bottom portion of panel.

any help, thanks

Hi senthil,

Could you possibly show more code? I am still unsure of how many panels there are.



hey man try using this
1)use the method setPrefferedSize() instead of setSize for the JPanel

check this code

import javax.swing.;
import javax.swing.event.
import java.awt.*;

public class jp extends JFrame {

public jp()

JFrame jfr = new JFrame("Frame");

//create a jpanel with null layout//
JPanel jpn = new JPanel();

//create two label and add inside the jpanel, one at top and one at bottom
	JLabel label1, label2,label3;
	label1 = new JLabel("Label 1"); label1.setBounds(2, 2, 100, 25);
	label2 = new JLabel("Label 2"); label2.setBounds(2, 300, 100, 25);
	label3 = new JLabel("Label 3"); label3.setBounds(250, 350, 100, 25);
	jpn.add(label1); jpn.add(label2);
	//set jpanel size[viewable] to 180 x 350
	jpn.setPreferredSize(new Dimension(300, 400));
	//create scrollable component and assign jpanel to be view
	JScrollPane jsp = new JScrollPane(jpn);
	//set jscrollpane size to 200x150
	jsp.setBounds(2, 2, 200, 150);
	jfr.setSize(210, 180);


public static void main(String s[]) {

jp j=new jp();


I have a similar problem in regards to jTabbedPane and jScrollPane with additional jtable.
Here’s partial of my codes.

    jTable1 = new javax.swing.JTable();
    jScrollPane1 = new javax.swing.JScrollPane(jTable1);

    jtp = new JTabbedPane();
    jp1 = new JPanel();

Problem now is the jTabbedPane is not displayed out =(
Please help