PDA

Click to See Complete Forum and Search --> : set form location and unmovable


Winanjaya
Jan 12th, 2010, 09:16 AM
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

ComputerJy
Jan 12th, 2010, 04:37 PM
Basically you have to do this: 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);
}
}

Winanjaya
Jan 13th, 2010, 07:14 AM
thanks, but it still movable.. ;<)

kfcSmitty
Jan 13th, 2010, 09:32 AM
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;


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?

ComputerJy
Jan 13th, 2010, 03:32 PM
I'd go for a notification dialog like the one in IMs

Winanjaya
Jan 13th, 2010, 06:55 PM
Thanks a lot!