Solved

dialog recenters by itself

Posted on 1998-04-12
4
224 Views
Last Modified: 2010-04-16
I have a dialog that I hide and show a few times, I am referring to one dialog object.
When run under one JVM (Symantec Cafe), the dialog stays positioned where it was before
it was previously hidden. I like it that way.
When run under Sun's JVM or Netscape, the dialog is recentered on its parent every time it
is reshown.

Is there a simple way I can overcome this (except saving coordinates and moving the dialog by
myself) ?
0
Comment
Question by:mco
  • 2
4 Comments
 

Expert Comment

by:mparekh
ID: 1234048
when you are creating the dialog, it depends on the parent frame where it is positioned.
If you are passing the current frame pointer, then it will always open up at the centre of the parent frame.
Rather the center of the Frame and the center of the dialog
co-incide. So maybe Symantec's JVM has a bug. The way sun's JVM behaves is the right way.
0
 
LVL 1

Author Comment

by:mco
ID: 1234049
You are right with regard to CREATION, but I am referring to re-showing, i.e. calling
setVisible(false), and then setVisible(true).
BTW, I checked more carefully:, Sun's JVM behaves like this on Solaris, but Sun's
JVM on W95 behaves as I expect (the dialog stays where it was).

0
 
LVL 4

Accepted Solution

by:
evijay earned 150 total points
ID: 1234050
Hi,

I am using jdk1.1.6 (now available for download from sun site) and i didnt face this problem. I am giving you a sample test program. This program displays a push button. When you click on it, it displays a dialog. move the dialog at what ever place you want and press close button on the dialog. Then again if you press the "push" button on main frame the dialog reappears in the same position as earlier. I am using show and hide for this purpose.

import java.awt.*;
import java.awt.event.*;
public class TestDialog extends Frame {
      Dialog dlg;
      TestDialog()
      {
            super("Testing dialogs");
            setLayout(new FlowLayout());
            Button b = new Button("Push Me");
             add(b);
            b.addActionListener(
                  new ActionListener() {
                        public void actionPerformed(ActionEvent e)
                        {
                            if (dlg == null) {
                              dlg = createModalDialog();
                            }
                              dlg.setVisible(true);
                        }
                  }
            );
            b = new Button("Exit");
             add(b);
            b.addActionListener(
                  new ActionListener() {
                        public void actionPerformed(ActionEvent e)
                        {
                              System.exit(1);
                        }
                  }
            );
            setSize(200, 200);
            addWindowListener(
                new WindowAdapter() {
                  public void windowClosing(WindowEvent e)
                  {
                        System.exit(1);
                  }
                }
            );
      }
      public void hideDialog(Component src)
      {
            for (Component parent = src;
                        parent != null; parent = parent.getParent()) {
                  if (parent instanceof Dialog) {
                        parent.setVisible(false);
//                        ((Dialog)parent).dispose();
                        break;
                  }
            }
      
      }

      private Dialog createModalDialog()
      {
            Dialog dialog = new Dialog(this, "TestDialog1", true);
            dialog.setSize(400, 400);
            Panel mainPanel = new Panel();
            mainPanel.setLayout(new BorderLayout());
            Panel contentPanel = new Panel();
            contentPanel.setLayout(new GridLayout(4, 2));
            contentPanel.add(new Label("Label1 : "));
            contentPanel.add(new TextField());
            contentPanel.add(new Label("Label2 : "));
            contentPanel.add(new TextField());
            contentPanel.add(new Label("Label3 : "));
            contentPanel.add(new Button("Button1"));
            contentPanel.add(new Label("Label4 : "));
            contentPanel.add(new Button("Button1"));

            mainPanel.add("Center", contentPanel);
            Button b2 = new Button ("Close");
            b2.addActionListener(
                  new ActionListener() {
                        public void actionPerformed(ActionEvent e)
                        {
                              hideDialog((Component) e.getSource());
                        }
                  }      
            );

            Panel buttonPanel = new Panel();
            FlowLayout fl;
            buttonPanel.setLayout(fl = new FlowLayout());
            fl.setAlignment(FlowLayout.CENTER);
            buttonPanel.add(b2);
            mainPanel.add("South", buttonPanel);
            dialog.add(mainPanel);
            dialog.addWindowListener(
                new WindowAdapter() {
                  public void windowClosing(WindowEvent e)
                  {
                              hideDialog((Component) e.getSource());
                  }
                }
            );
            return dialog;
      }
                              
      public static void main(String args[])
      {
            new TestDialog().setVisible(true);

      }
}


0
 
LVL 4

Expert Comment

by:evijay
ID: 1234051
So the problem is only on Solaris platform?

What window manager do you use? Don't forget that some window managers on Unix systems override the windows' locations on the screen to do a "wise" windows displaying. This is especially true with FVWM (I, II and 95). However, there is a way to set this functionality OFF on the config file of the window manager.

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse shortcuts 9 54
oracle 11g 23 80
fibonacci ten numbers 4 38
Java Restore security prompts not working 10 10
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question