Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: need help, Problem in JScrollPane

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default need help, Problem in JScrollPane

    Sir i have a problem with JScrollPane, it suppose to appear JScrollPane when they reach the limit size, but as you can see nothings happen, can someone help me with this one, that will be appreciated... thx

    Output:



    import javax.swing.*;
     
    import java.awt.*;
     
    public class test {
     
    	static int colsPass = 10, rowsPass = 10;
    	static int fHeight, fWidth;
    	static int[] colsAlign = new int[3];
    	static int[] rowsAlign = new int[3];
    	static int set = 0;
    	static int tCell = 0;
    	static int loop1, loop2;
     
    	public static void main(String[] args){
    		scrollPane();
    	}
     
    	private static void scrollPane() {
     
    		fWidth = ((colsPass*3)*20)+230;
    		fHeight = (colsPass*20)+200;
    		tCell = rowsPass * colsPass;
     
    		JFrame frame = new JFrame("test scroll");
    		frame.setSize(fWidth + 35, fHeight + 120);
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		JPanel panel = new JPanel();
    		panel.setLayout(null);
    		panel.setLocation(fWidth, fHeight);
    		frame.add(panel);
     
    		JPanel panel2 = new JPanel();
    		panel2.setLayout(null);
    		panel2.setLocation(fWidth, fHeight);
    		JScrollPane scroll = new JScrollPane(panel2);
    		scroll.setBounds(10, 10, fWidth, fHeight);
    		panel.add(scroll);
     
    		JTextField[] txtArray1 = new JTextField[tCell];
    		JTextField[] txtArray2 = new JTextField[tCell];
    		JTextField[] txtArray3 = new JTextField[tCell];
     
    		try {
    			rowsAlign[0] = 60;
    			rowsAlign[1] = 60;
    			rowsAlign[2] = 60;
    			for (loop1 = 0; loop1 <= rowsPass-1; loop1++){
    				colsAlign[0] = 60;
    				colsAlign[1] = (colsPass*25)+100;
    				colsAlign[2] = ((colsPass*2)*25)+140;
     
    				for (loop2 = 0; loop2 <= colsPass-1; loop2++){
    					txtArray1[set] = new JTextField("");
    					txtArray1[set].setBounds(colsAlign[0], rowsAlign[0], 20, 20);
    					panel2.add(txtArray1[set]);
    					colsAlign[0] += 25;
     
    					txtArray2[set] = new JTextField("");
    					txtArray2[set].setBounds(colsAlign[1], rowsAlign[1], 20, 20);
    					panel2.add(txtArray2[set]);
    					colsAlign[1] += 25;
     
    					txtArray3[set] = new JTextField("");
    					txtArray3[set].setBounds(colsAlign[2], rowsAlign[2], 20, 20);
    					panel2.add(txtArray3[set]);
    					colsAlign[2] += 25;
    					set++;
     
    				}
    				loop2 = 0;
    				rowsAlign[0] += 25;
    				rowsAlign[1] += 25;
    				rowsAlign[2] += 25;
    			}
    		}
    		catch (Exception e) {}
    		frame.setVisible(true);
    	}
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: need help, Problem in JScrollPane

    You set the layout of the JPanel within the JScrollPane to null which may be part of the problem. I'd recommend first setting up the panel with an appropriate layout (a combination of BoxLayouts with verticals and horizontals would work), all the while setting the preferred size (and maximums/minimums if necessary) of each component so it can let the JScrollPane know if it needs to scroll

  3. #3
    Junior Member
    Join Date
    Mar 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need help, Problem in JScrollPane

    how can i set up layout to JPanel, can you pls. give me some example. if you dont mind.

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need help, Problem in JScrollPane

    isn't ok to set an JScrollPane to JPanel and another JPanel within the JScrollPane ?

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: need help, Problem in JScrollPane

    You can set up a JPanel within a JPanel, for example, the following code will set up two JPanels with dimensions 200x200 adjacent to each other using the BoxLayout which I alluded to above (see How to Use BoxLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container) )
    Dimension dim = new Dimension(200,200);
    JPanel panel1 = new JPanel();
    panel1.setPreferredSize(dim);
    JPanel panel2 = new JPanel();
    panel2.setPreferredSize(dim);
    JPanel holder = new JPanel();
    holder.setLayout( new BoxLayout( holder, BoxLayout.LINE_AXIS ) );
    holder.add(panel1);
    holder.add(panel2);

  6. #6
    Junior Member
    Join Date
    Mar 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: need help, Problem in JScrollPane

    All done, thx for your help, i hope there's a lot of people like you in this forum, thx.. very appreciated.....

Similar Threads

  1. JScrollPane
    By MysticDeath in forum AWT / Java Swing
    Replies: 1
    Last Post: February 17th, 2010, 10:21 PM
  2. JTable in JScrollPane
    By alwayslearner in forum AWT / Java Swing
    Replies: 1
    Last Post: January 31st, 2010, 10:24 PM
  3. JTable in JScrollPane
    By alwayslearner in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: January 29th, 2010, 11:42 AM
  4. About Title border in jscrollpane
    By subhvi in forum AWT / Java Swing
    Replies: 2
    Last Post: December 15th, 2009, 12:45 AM
  5. Data is getting corrupt in Jscrollpane
    By ruchika in forum AWT / Java Swing
    Replies: 0
    Last Post: September 1st, 2009, 10:41 AM