3 Replies - 1465 Views - Last Post: 11 December 2012 - 04:46 PM Rate Topic: -----

#1 ssddii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-December 12

GridBagLayout text not appearing on top left corner of the frame

Posted 10 December 2012 - 07:03 PM

I cant see the text appearing from top left corner... how can i modify the code to do this

 


	JFrame frame= new JFrame("frame name");
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(500,500);
		 
		String t=Integer.toString(x);
		JPanel panel = new JPanel(new GridBagLayout());
		
		
		
		
		
		
		frame.getContentPane().add(panel, BorderLayout.NORTH);
		GridBagConstraints c= new GridBagConstraints();
		
	//	frame.add(panel);
		
		
		
		JLabel label= new JLabel(t);
		c.gridx=0;
		c.gridy=0;
		c.insets = new Insets(10, 10, 10, 10);
		panel.add(label,c);
		
		JLabel labe2= new JLabel("10");
		c.gridx=500;
		c.gridy=50;
		//c.insets = new Insets(10, 10, 10, 10);
		panel.add(labe2,c);
		








Is This A Good Question/Topic? 0
  • +

Replies To: GridBagLayout text not appearing on top left corner of the frame

#2 Sheph  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,020
  • Joined: 12-October 11

Re: GridBagLayout text not appearing on top left corner of the frame

Posted 10 December 2012 - 10:30 PM

Please be more specific. Where do you define label, etc.?
Was This Post Helpful? 0
  • +
  • -

#3 ssddii  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 10-December 12

Re: GridBagLayout text not appearing on top left corner of the frame

Posted 11 December 2012 - 03:05 PM

What i meant was i set the
 frame.getContentPane().add(panel, BorderLayout.NORTH);

command to NORTH as an example , even if i chane it to other options i cant see my label with coordinates (0,0) starting from top left corner of the frame...
Was This Post Helpful? 0
  • +
  • -

#4 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 822
  • View blog
  • Posts: 2,529
  • Joined: 29-July 11

Re: GridBagLayout text not appearing on top left corner of the frame

Posted 11 December 2012 - 04:46 PM

I don't know anything about gridbaglayout, but could it have something to do with labe2 and it's c.gridx = 500. I thought gridx and gridy were grid numbers, not pixels.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1