From owner-freebsd-java@FreeBSD.ORG Tue Dec 27 14:44:34 2005 Return-Path: X-Original-To: java@freebsd.org Delivered-To: freebsd-java@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1095D16A41F for ; Tue, 27 Dec 2005 14:44:34 +0000 (GMT) (envelope-from hwh@gddsn.org.cn) Received: from gddsn.org.cn (gddsn.org.cn [218.19.164.145]) by mx1.FreeBSD.org (Postfix) with ESMTP id D665143D5E for ; Tue, 27 Dec 2005 14:44:31 +0000 (GMT) (envelope-from hwh@gddsn.org.cn) Received: from [192.168.1.5] (unknown [61.144.137.75]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by gddsn.org.cn (Postfix) with ESMTP id A44D838CB41 for ; Tue, 27 Dec 2005 22:44:26 +0800 (CST) Message-ID: <43B15343.5@gddsn.org.cn> Date: Tue, 27 Dec 2005 22:44:19 +0800 From: Huang wen hui User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051212) X-Accept-Language: zh-cn,zh MIME-Version: 1.0 To: java Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 7bit Cc: Subject: getLocation() problem when using -Dawt.toolkit=sun.awt.X11.XToolkit under JDK1.5.0-p2 X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Dec 2005 14:44:34 -0000 hi, When JFrame resize, JFrame.getLocation() will return same location. using MToolkit or using JDK1.4.2 do not have this problem. there is the little samples: #cat WelcomeFrame.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class WelcomeFrame extends JFrame { JPanel contentPane; BorderLayout borderLayout1 = new BorderLayout(); JMenuBar jMenuBar1 = new JMenuBar(); JMenu jMenuFile = new JMenu(); JMenuItem jMenuFileExit = new JMenuItem(); JMenu jMenuHelp = new JMenu(); JMenuItem jMenuHelpAbout = new JMenuItem(); /** * Construct the frame */ public WelcomeFrame() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } /** * Component initialization * * @throws Exception exception */ private void jbInit() throws Exception { contentPane = (JPanel) this.getContentPane(); contentPane.setLayout(borderLayout1); this.setTitle("Welcome to JBuilder"); this.addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { this_componentResized(e); } }); this.setJMenuBar(jMenuBar1); this.setSize(new Dimension(400, 300)); jMenuFile.setText("File"); jMenuFileExit.setText("Exit"); jMenuFileExit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jMenuFileExit_actionPerformed(e); } }); jMenuFile.add(jMenuFileExit); jMenuHelp.setText("Help"); jMenuHelpAbout.setText("About"); jMenuHelpAbout.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jMenuHelpAbout_actionPerformed(e); } }); jMenuHelp.add(jMenuHelpAbout); jMenuBar1.add(jMenuFile); jMenuBar1.add(jMenuHelp); } /** * Overridden so we can exit when window is closed * * @param e WindowEvent */ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } /** * File | Exit action performed * * @param e ActionEvent */ public void jMenuFileExit_actionPerformed(ActionEvent e) { System.exit(0); } /** * Help | About action performed * * @param e ActionEvent */ public void jMenuHelpAbout_actionPerformed(ActionEvent e) { } public void this_componentResized(ComponentEvent e) { if(this.isShowing()){ System.out.println("JFrame location: " + this.getLocation()); System.out.println("JFrame locationOnScreen: " + this.getLocationOnScreen()); } } } #cat WelcomeApp.java import java.awt.*; import javax.swing.UIManager; public class WelcomeApp { boolean packFrame = false; /** * Construct the application */ public WelcomeApp() { WelcomeFrame frame = new WelcomeFrame(); //Pack frames that have useful preferred size info, e.g. from their layout //Validate frames that have preset sizes if (packFrame) frame.pack(); else frame.validate(); // Center the frame Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = frame.getSize(); if (frameSize.height > screenSize.height) frameSize.height = screenSize.height; if (frameSize.width > screenSize.width) frameSize.width = screenSize.width; frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); frame.setVisible(true); } /** * Main method * * @param args String[] */ static public void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { e.printStackTrace(); } new WelcomeApp(); } } output: JFrame location: java.awt.Point[x=600,y=450] JFrame locationOnScreen: java.awt.Point[x=600,y=450] JFrame location: java.awt.Point[x=600,y=450] JFrame locationOnScreen: java.awt.Point[x=0,y=34] JFrame location: java.awt.Point[x=600,y=450] JFrame locationOnScreen: java.awt.Point[x=600,y=450]