Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / Проблема с диалогами / 5 сообщений из 5, страница 1 из 1
28.03.2007, 11:23:54
    #34420800
aleksandy
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Проблема с диалогами
Делаю свой модальный диалог:
Код: plaintext
1.
2.
3.
4.
5.
DirectoriesForm(Frame f, String title) {
     super (f, title, true);
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    ...
}
В главной форме (наследник JFrame) есть такой метод:
Код: plaintext
1.
2.
3.
 public   void  createDialog(String title) {    
    JDialog DirectForm =  new  DirectoriesForm( this , title);
}

Почему диалог появляется не по центру главной формы?
...
Рейтинг: 0 / 0
28.03.2007, 11:43:27
    #34420903
Дуремар
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Проблема с диалогами
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
 import  java.awt.*;

     public   static   void  centerWindow(Window window, Window parent)
    {

        Point p;
        Dimension d;

        Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
         if  (parent ==  null  || !parent.isShowing())
        {
            p =  new  Point( 0 ,  0 );
            d = scr;
        }
         else 
        {
            p = parent.getLocation();
            d = parent.getSize();
        }
        Dimension w = window.getSize();

        p.x += (d.width - w.width) /  2 ;
        p.y += (d.height - w.height) /  2 ;

         if  (p.x <  0 )
        {
            p.x =  0 ;
        }
         else   if  (p.x + w.width > scr.width)
        {
            p.x = scr.width - w.width;
        }

         if  (p.y <  0 )
        {
            p.y =  0 ;
        }
         else   if  (p.y + w.height > scr.height)
        {
            p.y = scr.height - w.height;
        }

        window.setLocation(p);
    }

Перед тем, как сказать диалогу show вызови этот метод. Если parent не null - то отцентрирует диалог относительно parent. Если parent == null - то выведет диалог посередине экрана.
...
Рейтинг: 0 / 0
28.03.2007, 11:51:14
    #34420944
Jozic
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Проблема с диалогами
Java Doc setLocationRelativeTo
Код: plaintext
 public   void  setLocationRelativeTo(Component c)
Sets the location of the window relative to the specified component. If the component is not currently showing, or c is null, the window is centered on the screen. If the bottom of the component is offscreen, the window is placed to the side of the Component that is closest to the center of the screen. So if the Component is on the right part of the screen, the Window is placed to its left, and visa versa.

Parameters:
c - the component in relation to which the window's location is determined
Since:
1.4
...
Рейтинг: 0 / 0
28.03.2007, 12:07:23
    #34421028
aleksandy
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Проблема с диалогами
Спасибо. Помогло.
...
Рейтинг: 0 / 0
28.03.2007, 12:09:00
    #34421038
Дуремар
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Проблема с диалогами
Jozic Java Doc setLocationRelativeTo
Код: plaintext
 public   void  setLocationRelativeTo(Component c)
Sets the location of the window relative to the specified component. If the component is not currently showing, or c is null, the window is centered on the screen. If the bottom of the component is offscreen, the window is placed to the side of the Component that is closest to the center of the screen. So if the Component is on the right part of the screen, the Window is placed to its left, and visa versa.

Parameters:
c - the component in relation to which the window's location is determined
Since:
1.4
Упс... И на старуху бывает проруха Проглядел
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / Проблема с диалогами / 5 сообщений из 5, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]