Making my Container accept X and Y locations

cannot get any kind of content pane to accept x and y locations

Page 1 of 1

8 Replies - 568 Views - Last Post: 25 September 2009 - 08:57 PM Rate Topic: -----

#1 painkiller102  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 15
  • View blog
  • Posts: 281
  • Joined: 27-February 08

Making my Container accept X and Y locations

Post icon  Posted 25 September 2009 - 07:07 PM

This is almost for sure a noobie question, however i cannot seem to figure out how to make my Container put a JLabel on the Container at a specific x and y coordinate. I have tried a null layout and the JLabel never appears. The code below is me using a (JPanel) Container, and still it will not put the label at 0,0. it just centers it in the middle of the form?! any help is greatly appreciated! and thanks!
			setSize(5,100);
			setAlwaysOnTop(true);
			setBackground(Color.BLACK);
			JLabel lab = new JLabel("Test");
			Container wcp = (JPanel)this.getContentPane();
			wcp.add(lab);
			lab.setLocation(0, 0);



Is This A Good Question/Topic? 0
  • +

Replies To: Making my Container accept X and Y locations

#2 akj_  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 23-March 09

Re: Making my Container accept X and Y locations

Posted 25 September 2009 - 08:04 PM

whre did u get that set location method from?

This post has been edited by akj_: 25 September 2009 - 08:06 PM

Was This Post Helpful? 0
  • +
  • -

#3 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Making my Container accept X and Y locations

Posted 25 September 2009 - 08:12 PM

View Postakj_, on 25 Sep, 2009 - 07:04 PM, said:

whre did u get that set location method from?


its a method inherited from class Component..the method is correct..for the OP, can you post the whole class to give you a better response
Was This Post Helpful? 0
  • +
  • -

#4 painkiller102  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 15
  • View blog
  • Posts: 281
  • Joined: 27-February 08

Re: Making my Container accept X and Y locations

Posted 25 September 2009 - 08:19 PM

View Postakj_, on 25 Sep, 2009 - 07:04 PM, said:

whre did u get that set location method from?


I was googling some solutions and i kindof threw it together. I also tried using a null layout like listed about however i couldn't get that to work either oO. The only thing i have found is setting the GUI's up by rows and columns. I was hoping there was a way to set it up by Location (x and y grid). but the lack of solutions here tells me that its not as simple as i thought :blink: . Even thought i program in 90 percent java, when it comes to GUI creation I'm still used to C# forms!!! So hopefully someone here can give me a link or some suggestions on how to fix my problem lol, but if not ill have to experiment with other solutions!

View Postmostyfriedman, on 25 Sep, 2009 - 07:12 PM, said:

View Postakj_, on 25 Sep, 2009 - 07:04 PM, said:

whre did u get that set location method from?


its a method inherited from class Component..the method is correct..for the OP, can you post the whole class to give you a better response


yes u may have the whole class ^_~ thanks for asking. i had it in my mind that this was a quick and simple solution...but yea. i guess not. Heres the whole code:
	public class testWindow extends JWindow
	{
		public int width, height;
		public testWindow()
		{
			width = 5;
			height = 100;
			setSize(5,100);
			setAlwaysOnTop(true);
			setBackground(Color.BLACK);
			JLabel lab2 = new JLabel("WOW!");
			JLabel lab = new JLabel("Test");
			lab2.setLocation(10, 5);
			Container wcp = (JPanel)this.getContentPane();
			wcp.add(lab);
			wcp.add(lab2);
			lab.setLocation(0, 0);
			//Container wcp = this.getContentPane();
			//getContentPane().setLayout(new GridLayout());
			//wcp.setBackground(Color.RED);
			//wcp.add(lab);
			//lab.setLocation(0,0);
			addMouseListener(new MouseAdapter()
			{
				public void mouseEntered(MouseEvent e)
				{
					try
					{
						t2.cancel();
					}
					catch(Exception ex)
					{
					}
					t1 = new Timer();
					t1.schedule(new winShow(), 0,1*1);
				}
			});
			addMouseListener(new MouseAdapter()
			{
				public void mouseExited(MouseEvent e)
				{
					try
					{
						t1.cancel();
					}
					catch(Exception ex)
					{
					}
					t2 = new Timer();
					t2.schedule(new winHide(), 0,1*1);
				}
			});
			addMouseListener(new MouseAdapter()
			{
				public void mousePressed(MouseEvent e){
				m.setState(m.NORMAL);
				m.setSize(w,h);
				m.show();
				CloseWindow();
			 }
			});
		}
		public void ShowWindow()
		{
			setVisible(true);
		}
		public void CloseWindow()
		{
			setVisible(false);
		}
		public void resizeWindow(int width, int height)
		{
			setSize(width,height);
			this.width = width;
			this.height = height;
		}
		public int getWindowWidth()
		{
			return width;
		}
		public int getWindowHeight()
		{
			return height;
		}
	}



clearly there are some variables here that are not explained, but they are just timers to make the window minimize and maximize correctly! Just one class out of the many in the project, if you need any more info on my project don't be afraid to ask!
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Making my Container accept X and Y locations

Posted 25 September 2009 - 08:30 PM

The default layout for JWindow is BorderLayout
so can not specify X,Y coordinate for that layout
You will have to set your JWindow layout to null

And why using a JWindow instead of a JFrame ?
Was This Post Helpful? 0
  • +
  • -

#6 painkiller102  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 15
  • View blog
  • Posts: 281
  • Joined: 27-February 08

Re: Making my Container accept X and Y locations

Posted 25 September 2009 - 08:41 PM

View Postpbl, on 25 Sep, 2009 - 07:30 PM, said:

The default layout for JWindow is BorderLayout
so can not specify X,Y coordinate for that layout
You will have to set your JWindow layout to null

And why using a JWindow instead of a JFrame ?


My reason for using a JWindow is because a JFrame minimizes to the taskbar, and this program I wanted to be more unique and have it minimize wherever i wish and not appear in the taskbar at all. And this may seem like an idiotic thing, but I'm not sure how to set the JWindow layout to null.....My first time using them I'm afraid! :D

View Postpainkiller102, on 25 Sep, 2009 - 07:39 PM, said:

View Postpbl, on 25 Sep, 2009 - 07:30 PM, said:

The default layout for JWindow is BorderLayout
so can not specify X,Y coordinate for that layout
You will have to set your JWindow layout to null

And why using a JWindow instead of a JFrame ?


My reason for using a JWindow is because a JFrame minimizes to the taskbar, and this program I wanted to be more unique and have it minimize wherever i wish and not appear in the taskbar at all. And this may seem like an idiotic thing, but I'm not sure how to set the JWindow layout to null.....My first time using them I'm afraid! :D


scratch that. i set the layout to null by
setLayout(null);



but when i do:
lab.setLocation(0,0);
add(lab);



it does not appear on the window oO!
Was This Post Helpful? 0
  • +
  • -

#7 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Making my Container accept X and Y locations

Posted 25 September 2009 - 08:42 PM

in your constructor
setLayout(null);


Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Making my Container accept X and Y locations

Posted 25 September 2009 - 08:50 PM

View Postpainkiller102, on 25 Sep, 2009 - 07:41 PM, said:

My reason for using a JWindow is because a JFrame minimizes to the taskbar, and this program I wanted to be more unique and have it minimize wherever i wish and not appear in the taskbar at all. And this may seem like an idiotic thing, but I'm not sure how to set the


jframe.setUndecorated(true);

will do the job.. no bar, no button to resize or iconified
Was This Post Helpful? 0
  • +
  • -

#9 painkiller102  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 15
  • View blog
  • Posts: 281
  • Joined: 27-February 08

Re: Making my Container accept X and Y locations

Posted 25 September 2009 - 08:57 PM

View Postpbl, on 25 Sep, 2009 - 07:50 PM, said:

View Postpainkiller102, on 25 Sep, 2009 - 07:41 PM, said:

My reason for using a JWindow is because a JFrame minimizes to the taskbar, and this program I wanted to be more unique and have it minimize wherever i wish and not appear in the taskbar at all. And this may seem like an idiotic thing, but I'm not sure how to set the


jframe.setUndecorated(true);

will do the job.. no bar, no button to resize or iconified


Thanks, but the icon wasn't what i truly wanted gone. What i needed gone was the other image that is there to the right of your start menu. Like when you open up a new browser, you get that button that says the page name and you click on it to maximize and minimize? that's what i needed gone and the JWindow was the solution.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1