Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

dialog recenters by itself

Posted on 1998-04-12
4
Medium Priority
?
236 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 300 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

704 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