Что событие Java Swing может использоваться для знания, когда приложение закончило запускаться?

Пытались ли вы дать медиа-папке правильное разрешение?

6
задан Arnold Spence 2 May 2009 в 19:31
поделиться

4 ответа

Решение, с которым я столкнулся, было на самом деле комбинацией ответов Чарльза Марина и JRL (я одобрил оба ваших ответа за благодарность, спасибо). .

...
public class MyView extends FrameView implements WindowListener
...

и в своем конструкторе FrameView я добавил слушателя в основной фрейм приложения.

...
getFrame().addWindowListener((WindowListener) this);
...

Затем в моей реализации windowActivation я мог вызвать код, который мне нужно было упорядочить, и задать размер элемента управления на основном JPanel в зависимости от местоположения и размер других элементов управления.

public void windowActivated(WindowEvent e)
{
    // The application should now be finished doing its startup stuff.
    // Position and size a control based on other UI controls here
}
4
ответ дан 10 December 2019 в 02:53
поделиться

Я бы попробовал использовать getFrame (). IsValid ()

1
ответ дан 10 December 2019 в 02:53
поделиться

Я думаю, что вы хотите WindowAcactive. Взгляните на эту часть руководства .

3
ответ дан 10 December 2019 в 02:53
поделиться

I assume this is the WYSIWYG editor thing. I'm looking at NetBeans 6.1, so your experiences may vary.

The traditional way to layout Swing components is by using a LayoutManager (or LayoutManager2). According to the NetBeans help, the visual editor supports these so long as they don't require support for constraints.

The procedure goes something like this:

  1. Create a new JavaBean and have it implement LayoutManager (a BeanInfo is required too for palette support - you can create one by right-clicking the bean class)
  2. Build the project
  3. Right-click the bean and choose Tools > Add to Palette... and add it
  4. Right-click the panel for which you want to set the layout and select Set Layout > Your Bean Name

You may find the design-time experience somewhat lacking.

A sample layout implementation:

public class StepLayoutBean extends Object implements Serializable, LayoutManager {

    public void addLayoutComponent(String name, Component component) {
    }

    public void layoutContainer(Container container) {
        Dimension space = container.getSize();
        int xoffset = 0;
        int yoffset = 0;
        for (Component kid : container.getComponents()) {
            Dimension prefSize = kid.getPreferredSize();
            if (prefSize.width + xoffset > space.width) {
                xoffset = 0;
            }
            Rectangle bounds = new Rectangle(xoffset, yoffset, prefSize.width, prefSize.height);
            kid.setBounds(bounds);
            xoffset += prefSize.width;
            yoffset += prefSize.height;
        }
    }

    public Dimension minimumLayoutSize(Container container) {
        Dimension size = new Dimension();
        for (Component kid : container.getComponents()) {
            Dimension minSize = kid.getMinimumSize();
            size.width = minSize.width > size.width ? minSize.width : size.width;
            size.height += minSize.height;
        }
        return size;
    }

    public Dimension preferredLayoutSize(Container container) {
        Dimension size = new Dimension();
        for (Component kid : container.getComponents()) {
            Dimension prefSize = kid.getPreferredSize();
            size.width += prefSize.width;
            size.height += prefSize.height;
        }
        return size;
    }

    public void removeLayoutComponent(Component component) {
    }
}

If a custom layout doesn't fit the bill, have a look at the event bindings under the component's properties panel - though resizing that way might be a recipe for some kind of recursive event storm.

1
ответ дан 10 December 2019 в 02:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: