Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Java Components doing whatever they want !

setpreferredsize

  • Please log in to reply
2 replies to this topic

#1 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 02 December 2011 - 03:39 PM

Hello,

I have really stuck at this point. I have the code below:
mainBoard = new JPanel(new BorderLayout());
board = new JPanel(new BorderLayout());

for(int i=0; i<4; i++){
			
			if(i==0){
				JPanel arrowPanel = new JPanel();
				arrowPanel.setLayout(new FlowLayout());
				for(int k =0; k<4; k++){
					arrows[i][k] = new JCoordButton(up);
					arrows[i][k].setPreferredSize(new Dimension(40,40));
					arrowPanel.add(arrows[i][k]);
				}
				board.add(arrowPanel, BorderLayout.NORTH);
			}
			else if(i==1){
				JPanel	arrowPanel = new JPanel();
				arrowPanel.setLayout(new FlowLayout());
				for(int k =0; k<4; k++){
					arrows[i][k] = new JCoordButton(right);
					arrows[i][k].setPreferredSize(new Dimension(40,40));
					arrowPanel.add(arrows[i][k]);
				}
				board.add(arrowPanel, BorderLayout.PAGE_END);
			}
			else if(i==2){
				JPanel	arrowPanel = new JPanel();
				arrowPanel.setLayout(new FlowLayout());
				for(int k =0; k<4; k++){
					arrows[i][k] = new JCoordButton(down);
					arrows[i][k].setPreferredSize(new Dimension(40,40));
					arrowPanel.add(arrows[i][k]);
				}
				board.add(arrowPanel, BorderLayout.SOUTH);
			}
			else if(i==3){
				JPanel arrowPanel = new JPanel();
				arrowPanel.setLayout(new FlowLayout());
				for(int k =0; k<4; k++){
					arrows[i][k] = new JCoordButton(left);
					arrows[i][k].setPreferredSize(new Dimension(40,40));
					arrowPanel.add(arrows[i][k]);
				}
				board.add(arrowPanel, BorderLayout.PAGE_START);
			}
		}

board.add(colourBoard, BorderLayout.CENTER);
mainBoard.add(board, BorderLayout.CENTER);

The output is as shown below :
Untitled.png

You can imagine from my code that is not the result I want! So, what I'm doing wrong? Any idea?

Thank you,
toto_7
  • 0

"Programming is like **. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 03 December 2011 - 03:03 AM

NORTH == PAGE_START, SOUTH == PAGE_END
You're just overwriting what you added at the NORTH and PAGE_END
  • 0

#3 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 03 December 2011 - 06:29 PM

That's great :) Thank you wim DC change to WEST and EAST
  • 0

"Programming is like **. One mistake and you have to support it for the rest of your life."

-Michael Sinz





Also tagged with one or more of these keywords: setpreferredsize

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download