Jump to content

Java Components doing whatever they want !

- - - - -

  • Please log in to reply
2 replies to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
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 :
Attached File  Untitled.png   4.66K   9 downloads

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

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

-Michael Sinz

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
NORTH == PAGE_START, SOUTH == PAGE_END
You're just overwriting what you added at the NORTH and PAGE_END

#3
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
That's great :) Thank you wim DC change to WEST and EAST

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

-Michael Sinz




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users