Solved

dialog recenters by itself

Posted on 1998-04-12
4
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
login form jsp example 2 71
SequenceInputStream example 3 38
ejb message driven bean mdb creation steps 2 54
Tomcat 9 + java 8 error while trying to deploy a war file 2 853
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

734 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