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
Printable View
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
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);
}
}
thanks, but it still movable.. ;<)
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;
What exactly are you attempting to do?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);
I'd go for a notification dialog like the one in IMs
Thanks a lot!