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);
Making my Container accept X and Y locationscannot get any kind of content pane to accept x and y locations
Page 1 of 1
8 Replies - 470 Views - Last Post: 25 September 2009 - 08:57 PM
#1
Making my Container accept X and Y locations
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!
Replies To: Making my Container accept X and Y locations
#2
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
#3
Re: Making my Container accept X and Y locations
Posted 25 September 2009 - 08:12 PM
#4
Re: Making my Container accept X and Y locations
Posted 25 September 2009 - 08:19 PM
akj_, 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
mostyfriedman, on 25 Sep, 2009 - 07:12 PM, said:
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!
#5
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 ?
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 ?
#6
Re: Making my Container accept X and Y locations
Posted 25 September 2009 - 08:41 PM
pbl, 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 ?
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!
painkiller102, on 25 Sep, 2009 - 07:39 PM, said:
pbl, 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 ?
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!
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!
#7
Re: Making my Container accept X and Y locations
Posted 25 September 2009 - 08:42 PM
in your constructor
setLayout(null);
#8
Re: Making my Container accept X and Y locations
Posted 25 September 2009 - 08:50 PM
painkiller102, 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
#9
Re: Making my Container accept X and Y locations
Posted 25 September 2009 - 08:57 PM
pbl, on 25 Sep, 2009 - 07:50 PM, said:
painkiller102, 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.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|