Non main JFrame

If i wanted to make a non main JFrame what is the basic structure for it to open as a new frame not as an internal frame? How would i call this Frame at an event?

Sorry been feeling ill and I seem to not write what i mean and not remember things i already know. I meant to take the elements of the JFrame into it but i did it just after you answered with some tweeking anyway. Calling and passing values to it should be done like a normal class construction method. Thanks for helping me out anyway

Similar Messages

  • In Unix, main JFrame focus not regained after modal dialog exit.

    Hi all,
    I'm new to this forum so hopefully this is the right place to put this question.
    I have a relatively simple GUI application written in Java 6u20 that involves a main gui window (extends JFrame). Most of the file menu operations result in a modal dialog (either JFileChooser or JOptionPane) being presented to the user.
    The problem is that when running on Unix (HPUX), the process of changing focus to one of these modal dialogs occasionally results in a quick flash of the background terminal window (not necessarily that used to launch the Java), and the process of closing the modal dialogs (by any means, i.e. any dialog button or hitting esc) doesn't always return focus to the main extended JFrame object, sometimes it goes to the terminal window and sometimes just flashes the terminal window before returning to the main JFrame window.
    I think the problem is with the Unix window manager deciding that the main focus should be a terminal window, not my Java application, since the problem occurs in both directions (i.e. focus from main JFrame to modal dialog or vice versa).
    In most cases of JOptionPane, I DO specify that the main extended JFrame object is the parent.
    I've tried multiple things since the problem first occured, including multiple calls to a method which calls the following:
    .toFront();
    .requestFocus();
    .setAlwaysOnTop(true);
    .setVisible(true);
    ..on the main JFrame window (referred to as a public static object)...
    just before and after dialog display, and following selection of any button from the dialogs. This reduced the frequency of the problem, but it always tends to flash the terminal window if not return focus to it completely, and when it occurs (or starts to occur then gets worse) is apparently random! (which makes me think it's an OS issue)
    Any help appreciated thanks,
    Simon
    Self-contained compilable example below which has the same behaviour, but note that the problem DOESN'T occur running on Windows (XP) and that my actual program doesn't use auto-generated code generated by a guibuilder:
    * To change this template, choose Tools | Templates 
    * and open the template in the editor. 
    package example;  
    import javax.swing.JOptionPane;  
    * @author swg 
    public class Main {  
         * @param args the command line arguments 
        public static void main(String[] args) {  
            java.awt.EventQueue.invokeLater(new Runnable() {  
                public void run() {  
                    new NewJFrame().setVisible(true);  
    class NewJFrame extends javax.swing.JFrame {  
        /** Creates new form NewJFrame */ 
        public NewJFrame() {  
            initComponents();  
        /** This method is called from within the constructor to 
         * initialize the form. 
         * WARNING: Do NOT modify this code. The content of this method is 
         * always regenerated by the Form Editor. 
        @SuppressWarnings("unchecked")  
        // <editor-fold defaultstate="collapsed" desc="Generated Code">  
        private void initComponents() {  
            jMenuBar1 = new javax.swing.JMenuBar();  
            jMenu1 = new javax.swing.JMenu();  
            jMenuItem1 = new javax.swing.JMenuItem();  
            jMenu2 = new javax.swing.JMenu();  
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);  
            jMenu1.setText("File");  
            jMenuItem1.setText("jMenuItem1");  
            jMenuItem1.addActionListener(new java.awt.event.ActionListener() {  
                public void actionPerformed(java.awt.event.ActionEvent evt) {  
                    jMenuItem1ActionPerformed(evt);  
            jMenu1.add(jMenuItem1);  
            jMenuBar1.add(jMenu1);  
            jMenu2.setText("Edit");  
            jMenuBar1.add(jMenu2);  
            setJMenuBar(jMenuBar1);  
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());  
            getContentPane().setLayout(layout);  
            layout.setHorizontalGroup(  
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
                .addGap(0, 400, Short.MAX_VALUE)  
            layout.setVerticalGroup(  
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)  
                .addGap(0, 279, Short.MAX_VALUE)  
            pack();  
        }// </editor-fold>  
        private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {  
            int result = JOptionPane.showConfirmDialog(this, "hello");  
        // Variables declaration - do not modify  
        private javax.swing.JMenu jMenu1;  
        private javax.swing.JMenu jMenu2;  
        private javax.swing.JMenuBar jMenuBar1;  
        private javax.swing.JMenuItem jMenuItem1;  
        // End of variables declaration  
    }

    It won't comfort you much, but I had similar problems on Solaris 10, and at the time we traked them down to a known bug [6262392|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6262392]. The status of this latter is "Closed, will not fix", although it is not explained why...
    It's probably because the entry is itself related to another, more general, bug [6888200|http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=b6eea0fca217effffffffe82413c8a9fce16?bug_id=6888200], which is still open.
    So it is unclear whether this problem will be worked upon (I suspect that yes) and when (I suspect that... not too soon, as it's been dormant for several years!).
    None of our attempts (+toFront(...)+ etc...) solved the issue either, and they only moderately lowered the frequency of occurrence.
    I left the project since then, but I was said that the workaround mentioned in the first bug entry (see comments) doesn't work, whereas switching to Java Desktop instead of CDE reduced the frequency of the issues (without fixing them completely either) - I don't know whether it's an option on HPUX.
    Edited by: jduprez on Jul 9, 2010 11:29 AM

  • How can I make the main JFrame centered?

    I'm using netbeans to create my program. I'm currently using a JFrame to do all my GUI.
    My problem is that when I create other JFrames within the Main JFrame, I can center that window by using, nameFrame.setLocationRelativeTo(null);
    but I don't know how to do it on the main frame. The main frame doesn't have a variable name and plus I don't know where I would put the code in.

    Caarmel wrote:
    you can use
    super.setLocationRelativeTo(null);or
    this.setLocationRelativeTo(null);
    Or more simplysetLocationRelativeTo(null);db

  • How can I change a decorated JFrame to non-decorated JFrame?

    I want to change a decorated JFrame to a non-decorated JFame. The frame already shown on the screen. How can I do this?

    If I call dispose() and setVisible(), the window ID will be changed. I am working on Linux and need to communicate with other processes by window ID. Is there a method to set a frame decorate without change window ID?

  • Popup not in specified Component, but in main JFrame

    Hi,
    how do I make a popup appear inside the Component "owner" that is
    given as parameter to the show method?
    I have a JFrame containing a JPanel component in a GridBagLayout.
    The JPanel has a MouseListener, causing "MousePressed" to show a
    popup with a small textfield at the mouse position inside JPanel.
    The popup is called as follows:
    show(e.getComponent(), JTextField, e.getX(), e.getY());
    I also tried giving explicit parameters: show(JPanel, JTextField, 10, 10);
    However, the popup is not positioned inside the JPanel, but in the JFrame that
    contains the JPanel.
    Thanks for any help!
    Regards,
    Elke

    Sorry, my fault: I confused the constructor with the method.
    Below is a test code I made.
    Thanks again,
    Elke
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import javax.swing.*;
    public class PopupTest extends JFrame {
    private JPanel jContentPane = null;
    private JTabbedPane jTabbedPane = null;
    private JPanel jpTab1 = null;
    private JPanel jPanel = null;
    private Popup mousePopup = null;
    public static void main(String[] args) {
    PopupTest myPopup = new PopupTest();
    myPopup.show();
    public PopupTest() {
    super();
    this.setContentPane(getJContentPane());
    this.setSize(300,300);
    private JPanel getJContentPane() {
    if(jContentPane == null) {
    jContentPane = new javax.swing.JPanel();
    jContentPane.setLayout(new BorderLayout());
    jContentPane.add(getJTabbedPane(), BorderLayout.CENTER);
    return jContentPane;
    private JTabbedPane getJTabbedPane() {
    if (jTabbedPane == null) {
    jTabbedPane = new JTabbedPane();
    jTabbedPane.addTab("Tab1", null, getJpTab1(), null);
    return jTabbedPane;
    private JPanel getJpTab1() {
    if (jpTab1 == null) {
    jpTab1 = new JPanel();
    jpTab1.setLayout(new GridBagLayout());
    jpTab1.setName("Tab1");
    GridBagConstraints grid1 = new GridBagConstraints();
    grid1.gridx = 0;
    grid1.gridy = 0;
    jpTab1.add(getJPanel(), grid1);
    return jpTab1;
    private JPanel getJPanel() {
    if (jPanel == null) {
    jPanel = new JPanel() {
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    for(int h = 0;h<100;h++)
    for(int w = 0;w<100;w++)
    g.setColor(Color.blue);
    g.drawRect(w, h, 1, 1);
    jPanel.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    if (e.isPopupTrigger()) {
    int x = e.getX();
    int y = e.getY();
    JLabel mouseData = new JLabel("["+x+","+y+"]");
    // create popup at mouse position inside the JPanel:
    mousePopup = PopupFactory.getSharedInstance().getPopup(e.getComponent(), mouseData, x, y);
    // problem: popup not at mouse position inside JPanel, but at position x,y in the JFrame.
    // Also tried the following, but that didn't work either:
    //mousePopup = PopupFactory.getSharedInstance().getPopup(jPanel, mouseData, x, y);
    // Why is the "owner" parameter in the popup constructor ignored?
    mousePopup.show();
    jPanel.setPreferredSize(new Dimension(100,100));
    return jPanel;
    }

  • JPopupMenu goes behind main JFrame after checking/unchecking its Items.

    I've written the following stand-alone code, which basically contains a JFrame that includes a combination of JPopupMenu's and JMenu's. If user right-clicks on the JFrame, a JPopupMenu will popup, which contains a JMenu. This JMenu also includes another JPopupMenu that contains 4 JCheckBoxMenuItems.
    The problem that I'm facing is that, after I select one JCheckBoxMenuItem, the popup menu containing them, will go behind the JFrame. How can I get it to stay in front? Here's my SSCCE. I need to turn this in at work by tomorrow at the latest. So, if anyone has time, your help will be very much appreciated. Thanks!
    import java.awt.Color;
    import java.awt.Point;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JButton;
    import javax.swing.JCheckBoxMenuItem;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JPopupMenu;
    import javax.swing.SwingUtilities;
    public class MyPopupTest {
          * @param args
         public MyPopupTest(){}
         public void generateMenu()
              final JFrame frame = new JFrame("My Frame");
              frame.setSize(300,300);
              final JPopupMenu popupMenu = new JPopupMenu();
              final JMenu menu = new JMenu("My Menu");
              final JPopupMenu itemsPopupMenu = new JPopupMenu();
              final JButton okButton = new JButton("OK");
              final JCheckBoxMenuItem item1 = new JCheckBoxMenuItem("Item 1", true);
              final JCheckBoxMenuItem item2 = new JCheckBoxMenuItem("Item 2", false);
              final JCheckBoxMenuItem item3 = new JCheckBoxMenuItem("Item 3", true);
              final JCheckBoxMenuItem item4 = new JCheckBoxMenuItem("Item 4", false);
              itemsPopupMenu.add(item1);
              itemsPopupMenu.add(item2);
              itemsPopupMenu.add(item3);
              itemsPopupMenu.add(item4);
              itemsPopupMenu.add(okButton);
              menu.add(itemsPopupMenu);
              popupMenu.add(menu);
              frame.addMouseListener(new MouseAdapter()
                   public void mouseClicked(MouseEvent e)
                        if(SwingUtilities.isRightMouseButton(e))
                             frame.getContentPane().add(popupMenu);
                             popupMenu.setLocation(e.getPoint().x+50,e.getPoint().y);
                             popupMenu.setVisible(true);
              popupMenu.addMouseListener(new MouseAdapter()
                   public void mouseEntered(MouseEvent e)
                        itemsPopupMenu.setLocation(new Point(popupMenu.getWidth()+menu.getLocationOnScreen().x, menu.getLocationOnScreen().y));
                        itemsPopupMenu.setVisible(true);
              item1.addMouseListener(new MouseAdapter()
                   public void mousePressed(MouseEvent e)
                        popupMenu.setVisible(true);
                   public void mouseEntered(MouseEvent e)
                        item1.setBackground(Color.PINK);
                   public void mouseExited(MouseEvent e)
                        item1.setBackground(popupMenu.getBackground());
              item2.addMouseListener(new MouseAdapter()
                   public void mousePressed(MouseEvent e)
                        popupMenu.setVisible(true);
                   public void mouseEntered(MouseEvent e)
                        item2.setBackground(Color.PINK);
                   public void mouseExited(MouseEvent e)
                        item2.setBackground(popupMenu.getBackground());
              item3.addMouseListener(new MouseAdapter()
                   public void mousePressed(MouseEvent e)
                        popupMenu.setVisible(true);
                   public void mouseEntered(MouseEvent e)
                        item3.setBackground(Color.PINK);
                   public void mouseExited(MouseEvent e)
                        item3.setBackground(popupMenu.getBackground());
              item4.addMouseListener(new MouseAdapter()
                   public void mousePressed(MouseEvent e)
                        popupMenu.setVisible(true);
                   public void mouseEntered(MouseEvent e)
                        item4.setBackground(Color.PINK);
                   public void mouseExited(MouseEvent e)
                        item4.setBackground(popupMenu.getBackground());
              okButton.addMouseListener(new MouseAdapter()
                   public void mousePressed(MouseEvent e)
                        popupMenu.setVisible(false);
                        itemsPopupMenu.setVisible(false);
              frame.setVisible(true);
         public static void main(String [] args)
              MyPopupTest test  = new MyPopupTest();
              test.generateMenu();
    }

    Quit multi-posting. This is your third posting on this topic. Others have no idea what has already been suggested in the other postings and are wasting their time reading the posting. Keep the discussion in a single posting.
    In fact I already explained to you how you can prevent the popup menu from closing and gave you a simple example to work from. For those of you that are curious. If you add a JCheckBox to a JPopupMenu, instead of a JCheckBoxMenuItem, the popup will stay open.
    I can't explain the behaviour of the posted code, but when you have a smiple working solution maybe its time to use it as the basis of your solution.

  • How do I add multiple JInternalFrames to 1 main JFrame

    It may seem like a silly question but I'd really appreciate any help offered. Sample code might be of assistance.
    Thanks people :-)

    It's very simple. Create a JFrame,
    then create separate classes for each JInternalFrame (here: TFrame, SFrame, GFrame)
    Here's some code:
    public class GWorkBench extends JFrame {
    public GWorkBench() {
    //Set up the GUI.
    desktop = new JDesktopPane(); //a specialized layered pane
    setContentPane(desktop);
    setJMenuBar(createMenuBar());
    protected JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Modules");
    menu.setMnemonic(KeyEvent.VK_D);
    JMenuItem menuItem1 = new JMenuItem("Data Entry");
    JMenuItem menuItem2 = new JMenuItem("Search Module");
    JMenuItem menuItem3 = new JMenuItem("Generation Module");
    menuItem1.setMnemonic(KeyEvent.VK_E);
    menuItem2.setMnemonic(KeyEvent.VK_S);
    menuItem3.setMnemonic(KeyEvent.VK_G);
    menuItem1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    createTFrame();
    menuItem2.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
              createSFrame();
    menuItem2.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
              createGFrame();
    menu.add(menuItem1);
    menu.add(menuItem2);
    menu.add(menuItem3);
    menuBar.add(menu);
    return menuBar;

  • Can't sync Centro (AT&T) with Outlook 2003 - on non main user account

    Hi
    I have a Centro (AT&T) and Outlook 2003, Vista Home
    Our main user account ("L*******) can install the Palm Desktop software from a CD (that came with the Centro in May 2008) and from PalmDesktopWin62.exe (72MB).
    It ask for a user name of which I give it "K****" (letters removed on purpose). It ask me to connect the Centro and shows that it is using Outlook.  An Outlook email account is NOT set up on this user account on the laptop.  When I go to the HotSync Manager, it shows under Applications ~ Outlook, etc.
    On user account (K*****) on same laptop, when I try to sync above phone, it asked to set up another account "K****" on this PC to which I reply Yes.  Then when it starts the HotSync it is using Palm Desktop as it has under applications ~ Date Book, Address Book,To Do List, Memo Pad instead of the Outlook name of Calendar, Contacts, Tasks, Memos.
    I have done many hard resets on the Centro.  I have uninstalled and reinstalled the software from the CD & download several times also removing all the Palm OS files under all the user accounts on the laptop.
    I've tried installing both methods of software under the main account (L****) and the secondary account (K****) both as adminstrators.
    So my question: what am I doing wrong or can you only run an outlook sync from the primary account on a laptop?
    Also, I'm currently running all of the above on another computer but only using the primary account and not having problems.
    Thanks so much for your time!!!
    Post relates to: Centro (AT&T)

    Ok it sounds like that you have a username setup on the device. Now to get this synced with outlook we need to delete the current account setup on the PC in Palm Desktop. First we need to setup a username called test. Once that is setup then delete the other account and then sync the device. Once the device is done syncing go to Start-->Programs-->Palm-->PIM conduit sync--> sync with outlook. Click ok then done. Then sync again.
    To delete and add an account in the hotsync manager, open up the hotsync manger and select user accounts. Once in there click on add and type in test. Then click ok. Select the other username that looks like yours and delete it.

  • Noobie question: How do I add something to the display list from a non-main class?

    I know how to use addChild() within the main class to add
    something to the stage display list and have it appear on the
    screen, but how do I add something to the stage display list from
    code within another class?
    So for example say I want to add some text (myTextField) to
    the stage's display list from within NotTheMainClass' code, could
    you give an example of the necessary code?

    you must pass a reference to a display list object or create
    one that's available to your class.
    there are so many ways to do this i'm not sure how you want
    to proceed. but you can create a globally available reference to
    the stage and root timeline:

  • Min-width for non-main-window

    Yet another case where the developer's stupid idea of implementing a minimum window width causes a problem...
    My work involves opening many separate browser windows, resizing them (sometimes quite small) and tiling them all over. This wasn't a problem (aside from firefox's well known and never-to-be-fixed massive memory leaks) until our IT decided to update to version 33 today (not certain what version we had previously but it was prior to the min-width fiasco was added). Now I can no longer make my many windows as small as they need to be.
    I've found the userChrome.css "fix" - https://support.mozilla.org/en-US/questions/980033
    This DOES work for the main window only, but does not allow for the resizing of my secondary windows. I don't know what kind of windows they are, the system we use has a button to press which detaches new windows for each product we must watch. They're popup windows of some kind, they have address bars, but nothing else that comes with the main window (e.g. search bar, home/stop/refresh/ect. buttons).
    Is there a userChrome.css command I can use that will allow these popup windows to break firefox's stupid min-width setting like the main window? I've tried duplicating the main-window command substituting #window #new-window #popup-window and a few others all to no avail.

    You can use the DOM Inspector to check what CSS rules are active in the pop-up window and use the !important flag to override the min-width with a lower value.
    *DOM Inspector: https://addons.mozilla.org/firefox/addon/dom-inspector-6622/
    *https://developer.mozilla.org/DOM_Inspector
    *https://developer.mozilla.org/Introduction_to_DOM_Inspector

  • Non-Rectangular JFrames using JNA or IBM IFrame

    Hi,
    I want to make a non-rectangular frame with round-shaped edges. I searched through this forum. But still unsuccessful. I can even go for a platform dependent solution. But i don't want to use Robot class which is taking screen-captures at interval or at system-events. This approach is very slower and faulty. Is anybody having experience in using JNA or IBM IFrame libraries (or any other approach) for this purpose?
    Thanks in advance,
    Sunil

  • JPanel inside a main JFrame (Internal Panel) realtime graphing

    Hello All,
    I am looking for assistance. I am working on a project where I need to log realtime stream of data coming from a 3 axis digital accelerometer which is connected to a PIC16F877A I/LP which in turn sends its data packets to an onboard bluetooth module and finally this data should be returned to an internal Jpanel in my GUI application. The issues are: when I click on the menu item to display the internal panel, I need to be able to see the 3 axis data being written onto the Jpanel. This whole process is a bit confusing to me, but I have a feeling it can still be done. Can you help me please?
    Mark

    rotnevni wrote:
    Thanks, the information is very helpful, however please allow me to actually present a question or two. Creating the GUI was pretty easy while using Netbeans IDE 6.7.1, but I'm trying to add the TODO handling code for some menu items in my GUI. For example, how do I launch an internal JPanel that will contain a text area (where the numerical data will display in realtime )? The idea here is when the GUI application is launched, the only thing visible to the user is an empty main frame with a menu bar containing menu items. When a menu item is clicked, a jpanel should appear and have some functionality within the context of that menu item, so each menu item for example, 3 axis mode, numerical mode, pass/fail mode, etc will have their own panel which appears only when that particular menu item is clicked and it appears inside the main frame. I hope I have explained my difficulties well enough to get more of your help. This should be just a simple setter type of call: your internal JPanel will have visibility to your parent, which I will assume, is where you will be collecting the data.
    The data from the accelerometer should be output to XML and or text. most preferably XML (two other menu items). Does the use of threads come into play ????
    As I become more exposed to writing the code I will improve.Are you using an XML Db, XML files, or are you streaming to one large file.

  • Need a non rectangular JFrame

    Hi,
    Does anyone know if its possible to have a GUI which is displayed in a frame which is not rectangular?
    I want to have an elliptical Frame to my GUI.
    I know its possible in other languages because I have seen a GUI for a media player which is not rectangular at all.
    Can anyone please help?
    Thanks,
    Jim

    I understand that in a parallel univers, where everyone live on ships, the most popula operating system is called Portholes 2000, which runs on computers with circular CRTs.
    Sadly, we're stuck with rectangular CRTs, Windows, windows and JFrames.

  • None rectangle JFrame or JWindow

    hi everyone
    how i can make none rectangle form with swing and pure java code.
    that is possible?
    thanks

    non-rectangular or transparent top-level frames are currently not supported. I remember seeing a RFE about it already, you might want to check the bug (rfe) database.

  • Problems with 'background' JFrame focus when adding a modal JDialog

    Hi all,
    I'm trying to add a modal JDialog to my JFrame (to be used for data entry), although I'm having issues with the JFrame 'focus'. Basically, at the moment my program launches the JFrame and JDialog (on program load) fine. But then - if I switch to another program (say, my browser) and then I try switching back to my program, it only shows the JDialog and the main JFrame is nowhere to be seen.
    In many ways the functionality I'm looking for is that of Notepad: when you open the Find/Replace box (albeit it isn't modal), you can switch to another program, and then when you switch back to Notepad both the main frame and 'JDialog'-esque box is still showing.
    I've been trying to get this to work for a couple of hours but can't seem to. The closest I have got is to add a WindowFocusListener to my JDialog and I hide it via setVisible(false) once windowLostFocus() is fired (then my plan was to implement a similar functionality in my JFrame class - albeit with windowGainedFocus - to show the JDialog again, i.e. once the user switches back to the program). Unfortunately this doesn't seem to work; I can't seem to get any window or window focus listeners to actually fire any methods, in fact?
    I hope that kind of makes sense lol. In short I'm looking for Notepad CTRL+R esque functionality, albeit with a modal box. As for a 'short' code listing:
    Main.java
    // Not all of these required for the code excerpt of course.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GraphicsEnvironment;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ComponentAdapter;
    import java.awt.event.ComponentEvent;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowFocusListener;
    import java.awt.event.WindowListener;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSplitPane;
    import javax.swing.UIManager;
    import javax.swing.plaf.basic.BasicSplitPaneDivider;
    import javax.swing.plaf.basic.BasicSplitPaneUI;
    public class Main extends JFrame implements ActionListener, WindowFocusListener, WindowListener, FocusListener {
         static JFrame frame;
         private static int programWidth;
         private static int programHeight;
         private static int minimumProgramWidth = 700;
         private static int minimumProgramHeight = 550;
         public static SetupProject setupProjectDialog;
         public Main() {
              // Setup the overall GUI of the program
         private static void createSetupProjectDialog() {
              // Now open the 'Setup Your Project' dialog box
              // !!! Naturally this wouldn't auto-open on load if the user has already created a project
              setupProjectDialog = new SetupProject( frame, "Create Your Website Project", true );
              // Okay, for this we want it to be (say) 70% of the progamWidth/height, OR *slightly* (-25px) smaller than the minimum size of 700/550
              // Change (base on programWidth/Height) then setLocation
              int currProgramWidth = getProgramWidth();
              int currProgramHeight = getProgramHeight();
              int possibleWidth = (int) (currProgramWidth * 0.7);
              int possibleHeight = (int) (currProgramHeight * 0.7);
              // Set the size and location of the JDialog as needed
              if( (possibleWidth > (minimumProgramWidth-25)) && (possibleHeight > (minimumProgramHeight-25)) ) {
                   setupProjectDialog.setPreferredSize( new Dimension(possibleWidth,possibleHeight) );
                   setupProjectDialog.setLocation( ((currProgramWidth/2)-(possibleWidth/2)), ((currProgramHeight/2)-(possibleHeight/2)) );
               else {
                   setupProjectDialog.setPreferredSize( new Dimension( (minimumProgramWidth-25), (minimumProgramHeight-25)) );
                   setupProjectDialog.setLocation( ((currProgramWidth/2)-((minimumProgramWidth-25)/2)), ((currProgramHeight/2)-((minimumProgramHeight-25)/2)) );
              setupProjectDialog.setResizable(false);
              setupProjectDialog.toFront();
              setupProjectDialog.pack();
              setupProjectDialog.setVisible(true);
         public static void main ( String[] args ) {
              Main frame = new Main();
              frame.pack();
              frame.setVisible(true);
              createSetupProjectDialog();
            // None of these get fired when the Jframe is switched to. I also tried a ComponentListener, but had no joy there either.
         public void windowGainedFocus(WindowEvent e) {
              System.out.println("Gained");
              setupProjectDialog.setVisible(true);
         public void windowLostFocus(WindowEvent e) {
              System.out.println("GainedLost");
         public void windowOpened(WindowEvent e) {
              System.out.println("YAY1!");
         public void windowClosing(WindowEvent e) {
              System.out.println("YAY2!");
         public void windowClosed(WindowEvent e) {
              System.out.println("YAY3!");
         public void windowIconified(WindowEvent e) {
              System.out.println("YAY4!");
         public void windowDeiconified(WindowEvent e) {
              System.out.println("YAY5!");
         public void windowActivated(WindowEvent e) {
              System.out.println("YAY6!");
         public void windowDeactivated(WindowEvent e) {
              System.out.println("YAY7!");
         public void focusGained(FocusEvent e) {
              System.out.println("YAY8!");
         public void focusLost(FocusEvent e) {
              System.out.println("YAY9!");
    SetupProject.java
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowFocusListener;
    import java.awt.event.WindowListener;
    import java.io.IOException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    public class SetupProject extends JDialog implements ActionListener {
         public SetupProject( final JFrame frame, String title, boolean modal ) {
              // Setup the JDialog
              super( frame, title, modal );
              setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );
              // Bad code. Is only temporary
              add( new JLabel("This is a test.") );
              // !!! TESTING
              addWindowFocusListener( new WindowFocusListener() {
                   public void windowGainedFocus(WindowEvent e) {
                        // Naturally this now doesn't get called after the setVisible(false) call below
                   public void windowLostFocus(WindowEvent e) {
                        System.out.println("Lost");
                        setVisible(false); // Doing this sort of thing since frame.someMethod() always fires a null pointer exception?!
    }Any help would be very much greatly appreciated.
    Thanks!
    Tristan

    Hi,
    Many thanks for the reply. Isn't that what I'm doing with the super() call though?
    As in, in Main.java I'm doing:
    setupProjectDialog = new SetupProject( frame, "Create Your Website Project", true );Then the constructor in SetupProject is:
    public SetupProject( final JFrame frame, String title, boolean modal ) {
              // Setup the JDialog
              super( frame, title, modal );
              And isn't the super call (since the class extends JDialog) essentially like doing new JDialog(frame,title,modal)?
    If not, that would make sense due to the null pointer exception errors I've been getting. Although I did think I'd done it right hence am confused as to the right way to handle this,if so.
    Thanks,
    Tristan
    Edited by: 802573 on 20-Oct-2010 08:27

Maybe you are looking for

  • How do I see Thumbnail view in Safari? iOS6

    I've just watched a video on icons for iPad, and the guy switches between the screens via Thumbnails.  So you can see at a glance, what's what.  Very useful if you have various pages open that are from the same site, and the <title> of the page is mo

  • PLSQL - Like statment

    can i add parameter to like statment in PLSQL code : select * from abcd where any_value like '%input parameter %' thanks

  • Do I Need COsting Sheet

    Hi all CO Gurus, I have a scenario where for all cost estimated (std cost), the overheads for General and Admin are based on forecast for current year. However, the formula actually has a weight factor acctached to it to split forecast overheads betw

  • Finished Goods at  Moving average Price.

    Hi Experts, In my company FG maintained at Moving average price, during the Go-live they fed the value manually in material master of FG. Now at the time of production conformation system considering BOM for consumption, but for cost of production sy

  • How to override attributes of one class into another class in OOPS ABAP

    I was trying to override attribute(data memeber) defined in super class into subclass , but I didnt find any solution to that. Please tell me ho to do that? Ex Class ABC definition       Public section          data : x type i.    end class Calss XYZ