1. Positioning dialogs on screen... coderanch.comSometimes you need to display a dialog window on screen, so that it will be center-aligned on parent's window. But how to do this if you have no reference to parent window, for example when overriding actionPerformed() method. Now I doing it like that: if( e.getSource() instanceof Component ) { Component comp = (Component) e.getSource(); Frame[] frms = Frame.getFrames(); for( int ... |
2. JDialog positioning coderanch.comtry this package testing; import javax.swing.*; import java.awt.*; import java.awt.event.*; import org.w3c.dom.*; import java.util.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; import java.io.*; import java.math.*; public class about extends JPanel { public about() { JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); menu.setMnemonic(KeyEvent.VK_F); JMenuItem aboutItem = new JMenuItem("about", KeyEvent.VK_A); menu.add(aboutItem); aboutItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { aboutItem_actionPerformed(e); } ... |
3. JDialog positioning coderanch.comIs it my imagination, or is this the perfect illustration of how important is the skill of naming? getLocation() should return the "default" location, or the location on the screen. And the method that returns the location of a component relative to its parent container should have the word "relative" in it. getRelativeLocation() or something like that. Well... it's free code... ... |