|
-
Jan 12th, 2010, 10:16 AM
#1
Thread Starter
Fanatic Member
set form location and unmovable
Hello Senior,
I am new to Java, I am trying to set form1 location to the top of tray icon and not movable, how to do this?
please help
thanks & regards
-
Jan 12th, 2010, 05:37 PM
#2
Re: set form location and unmovable
Basically you have to do this:
Code:
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
public class Test {
public static void main(final String[] args) {
final JFrame frm = new JFrame("Test");
// initialization
frm.setSize(100, 200);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Removing the title bar
frm.setUndecorated(true);
// Setting the location according to the screen and window sizes
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frm.setLocationByPlatform(false);
frm.setLocation(screenSize.width - frm.getWidth(), screenSize.height - frm.getHeight());
// Showing the JFrame
frm.setVisible(true);
}
}
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jan 13th, 2010, 08:14 AM
#3
Thread Starter
Fanatic Member
Re: set form location and unmovable
thanks, but it still movable.. ;<)
-
Jan 13th, 2010, 10:32 AM
#4
Re: set form location and unmovable
Expanding on ComputerJy's example, this will accomplish what you need, but it does add a flicker.
You will need
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
Code:
final JFrame frm = new JFrame("Test");
// initialization
frm.setSize(100, 200);
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Removing the title bar
frm.setUndecorated(true);
// Setting the location according to the screen and window sizes
final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frm.setLocationByPlatform(false);
frm.setLocation(screenSize.width - frm.getWidth(), screenSize.height - frm.getHeight());
frm.addComponentListener(new ComponentAdapter() {
public void componentMoved(ComponentEvent e) {
frm.setLocation(screenSize.width - frm.getWidth(), screenSize.height - frm.getHeight());
}
});
// Showing the JFrame
frm.setVisible(true);
What exactly are you attempting to do?
-
Jan 13th, 2010, 04:32 PM
#5
Re: set form location and unmovable
I'd go for a notification dialog like the one in IMs
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jan 13th, 2010, 07:55 PM
#6
Thread Starter
Fanatic Member
Re: set form location and unmovable
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|