Go Back   Java Programming Forums > Java Standard Edition Programming Help > AWT / Java Swing


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 13-03-2010, 01:35 PM
sny sny is offline
Junior Member
 

Join Date: Mar 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
sny is on a distinguished road
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:



Java Code
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);
	}
}



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
  #2 (permalink)  
Old 13-03-2010, 03:52 PM
copeg's Avatar
Moderator
 
9 Highscores

Join Date: Oct 2009
Posts: 570
Thanks: 7
Thanked 131 Times in 125 Posts
copeg will become famous soon enoughcopeg will become famous soon enough

I'm feeling Sleepy
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
Reply With Quote
  #3 (permalink)  
Old 15-03-2010, 12:59 AM
sny sny is offline
Junior Member
 

Join Date: Mar 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
sny is on a distinguished road
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.
Reply With Quote
  #4 (permalink)  
Old 15-03-2010, 01:05 AM
sny sny is offline
Junior Member
 

Join Date: Mar 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
sny is on a distinguished road
Default Re: need help, Problem in JScrollPane

isn't ok to set an JScrollPane to JPanel and another JPanel within the JScrollPane ?
Reply With Quote
  #5 (permalink)  
Old 15-03-2010, 01:12 AM
copeg's Avatar
Moderator
 
9 Highscores

Join Date: Oct 2009
Posts: 570
Thanks: 7
Thanked 131 Times in 125 Posts
copeg will become famous soon enoughcopeg will become famous soon enough

I'm feeling Sleepy
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) )
Java Code
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);
Reply With Quote
  #6 (permalink)  
Old 15-03-2010, 11:16 AM
sny sny is offline
Junior Member
 

Join Date: Mar 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
sny is on a distinguished road
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.....
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
JScrollPane MysticDeath AWT / Java Swing 1 18-02-2010 02:21 AM
JTable in JScrollPane alwayslearner AWT / Java Swing 1 01-02-2010 02:24 AM
JTable in JScrollPane alwayslearner File I/O & Other I/O Streams 0 29-01-2010 03:42 PM
About Title border in jscrollpane subhvi AWT / Java Swing 2 15-12-2009 04:45 AM
Data is getting corrupt in Jscrollpane ruchika AWT / Java Swing 0 01-09-2009 03:41 PM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 01:57 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.