Results 1 to 6 of 6

Thread: set form location and unmovable

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    784

    Question 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

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    784

    Re: set form location and unmovable

    thanks, but it still movable.. ;<)

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    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?

  5. #5
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2003
    Posts
    784

    Re: set form location and unmovable

    Thanks a lot!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width