Example usage for java.awt Container validate

List of usage examples for java.awt Container validate

Introduction

In this page you can find the example usage for java.awt Container validate.

Prototype

public void validate() 

Source Link

Document

Validates this container and all of its subcomponents.

Usage

From source file:Main.java

/**
 * Calls {@link Container#validate()} then {@link Container#repaint()} on
 * the given {@link Container} to fully reload the Container.
 * //from   w  w  w  .j a  v  a 2s  .  c  om
 * @param c
 *            - the Container to use
 * @see Container#repaint()
 * @see Container#validate()
 */
public static void validate(Container c) {
    c.validate();
    c.repaint();
}

From source file:Main.java

public static void replaceComponent(Container cont, int index, Component comp) {
    cont.remove(index);//from  w ww . j  a  v  a2 s .c om
    // cont.validate();
    cont.add(comp, index);
    cont.validate();
    cont.repaint();
}

From source file:Main.java

public static void replaceComponent(Container cont, Component comp1, Component comp2, String constraints) {
    int index = -1;
    int i = 0;/*w  ww.j  a  v  a  2 s.  co  m*/
    for (Component comp : cont.getComponents()) {
        if (comp.equals(comp1)) {
            index = i;
            break;
        }
        ++i;
    }
    // cont.setIgnoreRepaint(true);
    cont.remove(comp1);
    cont.add(comp2, constraints, index);
    cont.validate();
    // cont.setIgnoreRepaint(false);
    cont.repaint();
}

From source file:BoxLayoutTest.java

public void actionPerformed(ActionEvent evt) {
    Container contentPane = getContentPane();
    contentPane.remove(currentBox);//from w  ww .  j  a va2s.  co  m

    if (horizontalButton.isSelected()) {
        if (strutsAndGlueCheckBox.isSelected()) {
            currentBox = horizontalStrutsAndGlueBox;
        } else {
            currentBox = horizontalBox;
        }
    } else {
        if (strutsAndGlueCheckBox.isSelected()) {
            currentBox = verticalStrutsAndGlueBox;
        } else {
            currentBox = verticalBox;
        }

    }

    contentPane.add(currentBox, "Center");
    contentPane.validate();
    repaint();
}

From source file:StackLayout.java

/**
 * Set the currently displayed component.  If passed null for the component,
 * all contained components will be made invisible (sliding windows do this)
 * @param c Component to show//  w  w  w. j a v  a  2  s . c o  m
 * @param parent Parent container
 */
public void showComponent(Component c, Container parent) {
    Component comp = getVisibleComponent();
    if (comp != c) {
        if (!parent.isAncestorOf(c) && c != null) {
            parent.add(c);
        }
        synchronized (parent.getTreeLock()) {
            if (comp != null) {
                comp.setVisible(false);
            }
            visibleComp = new WeakReference<Component>(c);
            if (c != null) {
                c.setVisible(true);
            }
            // trigger re-layout
            if (c instanceof JComponent) {
                ((JComponent) c).revalidate();
            } else {
                parent.validate(); //XXX revalidate should work!
            }
        }
    }
}

From source file:pt.lsts.neptus.plugins.sunfish.awareness.SituationAwareness.java

@Override
public void setActive(boolean mode, StateRenderer2D source) {
    super.setActive(mode, source);
    Container parent = source.getParent();
    while (parent != null && !(parent.getLayout() instanceof BorderLayout))
        parent = parent.getParent();/*www . ja  va 2s.  c  o m*/
    if (mode) {
        JPanel panel = new JPanel(new BorderLayout());
        panel.add(slider, BorderLayout.CENTER);
        panel.add(minTimeLabel, BorderLayout.WEST);
        panel.add(maxTimeLabel, BorderLayout.EAST);
        parent.add(panel, BorderLayout.SOUTH);
    } else {
        parent = slider.getParent().getParent();
        parent.remove(slider.getParent());
    }
    parent.invalidate();
    parent.validate();
    parent.repaint();

}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/** Resets the size of the components hosting this component.*/
private void resetComponentSize() {
    Container pane = getComponent(getParent());
    pane.setSize(getPreferredSize());//from   w  ww .  j  a  va 2  s .  co  m
    pane.validate();
    pane.repaint();
}

From source file:game.Clue.ClueGameUI.java

public void mouseReleased(MouseEvent e) {

    System.out.println("Mouse clicked/released on chosen room" + e.getSource().toString());

    if (player == null) {
        return;// w  w  w .  j av a 2s  .  c  o  m
    }

    //validate move by sending move request to Server before allowing move
    int valid = 1;

    player.setVisible(false);

    Component c = jPanel5.findComponentAt(e.getX(), e.getY());

    if (c instanceof JLabel) {
        Container parent = c.getParent();
        if (parent.getComponentCount() == 0) {
            System.out.println("------");
            //parent.remove(0);
            parent.add(player);

        } else {
            System.out.println("%%%%%");
            parent.add(player);
            parent.validate();
            //return;
        }

    } else {
        Container parent = (Container) c;
        if (parent.getComponentCount() == 1) {
            System.out.println("*****");
            return;
        } else {
            System.out.println("&&&&&");
            parent.add(player);
        }

    }
    if (valid != 0) {
        System.out.println("Player move allowed" + " x:" + e.getX() + "y: " + e.getY());
        System.out.println("Previous x:" + previous_room_x + "  Y:" + previous_room_y);
        player.setLocation(previous_room_x, previous_room_y);
        // player.setLocation(e.getX(),e.getY());
    } else {

    }
    player.setHorizontalAlignment(SwingConstants.CENTER);
    player.setVisible(true);

}

From source file:marytts.tools.voiceimport.DatabaseImportMain.java

/**
 * Run the selected components in a different thread.
 *
 *//*  w w  w  .  ja  v  a2  s.c o  m*/
protected void runSelectedComponents() {
    new Thread("RunSelectedComponentsThread") {
        public void run() {
            try {
                runButton.setEnabled(false);
                for (int i = 0; i < components.length; i++) {
                    if (checkboxes[i].isSelected()) {
                        boolean success = false;
                        Container parent = checkboxes[i].getParent();
                        final JProgressBar progress = new JProgressBar();
                        final VoiceImportComponent oneComponent = components[i];
                        if (oneComponent.getProgress() != -1) {
                            progress.setStringPainted(true);
                            new Thread("ProgressThread") {
                                public void run() {
                                    int percent = 0;
                                    while (progress.isVisible()) {
                                        progress.setValue(percent);
                                        try {
                                            Thread.sleep(500);
                                        } catch (InterruptedException ie) {
                                        }
                                        percent = oneComponent.getProgress();
                                    }
                                }
                            }.start();
                        } else {
                            progress.setIndeterminate(true);
                        }
                        parent.add(progress, BorderLayout.EAST);
                        progress.setVisible(true);
                        parent.validate();
                        try {
                            success = oneComponent.compute();
                        } catch (Exception exc) {
                            checkboxes[i].setBackground(Color.RED);
                            throw new Exception("The component " + checkboxes[i].getText()
                                    + " produced the following exception: ", exc);
                        } finally {
                            checkboxes[i].setSelected(false);
                            progress.setVisible(false);
                        }
                        if (success) {
                            checkboxes[i].setBackground(Color.GREEN);
                        } else {
                            checkboxes[i].setBackground(Color.RED);
                        }
                    }
                }
            } catch (Throwable e) {
                e.printStackTrace();
            } finally {
                runButton.setEnabled(true);
            }

        }
    }.start();
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/** 
 * Lays out the components composing main panel. 
 * // w ww . j  a  v  a 2s .com
 * @param fromPreferences   Pass <code>true</code> to indicate that the 
 *                      method is invoked while setting the user 
 *                      preferences, <code>false</code> otherwise.
 */
private void layoutComponents(boolean fromPreferences) {
    //initSplitPanes();
    Dimension d;
    int diff;
    Container container = getContentPane();
    container.removeHierarchyBoundsListener(boundsAdapter);
    int width = 0, height = 0;
    JComponent rightComponent;
    //int divider = 0;
    int vExtra = 2;
    int addition;
    switch (displayMode) {
    case RENDERER:
        rightComponent = model.getMetadataViewer().getEditorUI();
        rendererSplit.setRightComponent(rightComponent);
        if (restoreSize == null) {
            rendererSplit.setResizeWeight(1.0);
            return;
        }
        d = model.getMetadataViewer().getIdealRendererSize();
        rightComponent.setMinimumSize(d);
        tabs.setMinimumSize(restoreSize);
        height = restoreSize.height;
        diff = d.height - restoreSize.height;
        if (diff > 0)
            height += diff;
        else
            height += vExtra;
        addition = rendererSplit.getDividerSize() + 2 * (refInsets.left + refInsets.right);

        width = restoreSize.width + d.width;
        width += 4 * addition;
        break;
    case HISTORY:
        container.remove(mainComponent);
        historyUI.doGridLayout();
        addComponents(historySplit, tabs, historyUI);
        mainComponent = historySplit;
        container.add(mainComponent, BorderLayout.CENTER);
        container.validate();
        container.repaint();
        height = restoreSize.height;
        width = restoreSize.width;
        d = historyUI.getIdealSize();
        addition = historySplit.getDividerSize() + 2 * (refInsets.top + refInsets.bottom);
        height += d.height;
        historySplit.setResizeWeight(0.49);
        height += addition;
        break;
    case HISTORY_AND_RENDERER:
        historySplit.setResizeWeight(0.49);
        container.remove(mainComponent);
        historyUI.doGridLayout();
        rightComponent = model.getMetadataViewer().getEditorUI();
        addComponents(rendererSplit, tabs, rightComponent);
        addComponents(historySplit, rendererSplit, historyUI);
        mainComponent = historySplit;
        container.add(mainComponent, BorderLayout.CENTER);
        container.validate();
        container.repaint();

        d = model.getMetadataViewer().getIdealRendererSize();
        height = restoreSize.height;
        diff = d.height - restoreSize.height;
        if (diff > 0)
            height += diff;
        else
            height += vExtra;
        addition = rendererSplit.getDividerSize() + 2 * (refInsets.left + refInsets.right);

        width = restoreSize.width + d.width;
        width += 4 * addition;
        d = historyUI.getPreferredSize();
        addition = historySplit.getDividerSize() + 2 * (refInsets.top + refInsets.bottom);
        height += d.height;
        height += addition;
        break;
    case NEUTRAL:
        rightComponent = model.getMetadataViewer().getEditorUI();
        rendererSplit.remove(rightComponent);
        if (restoreSize == null)
            return;
        width = restoreSize.width;
        height = restoreSize.height;
        break;
    default:
    }
    //rendererSplit.setDividerLocation(-1);
    //rendererSplit.setResizeWeight(1.0);
    //historySplit.setDividerLocation(-1);
    d = getIdealSize(width, height);

    /* Need to review that code.
     * Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int w = (int) (screen.width*SCREEN_RATIO);
    int h = (int) (screen.height*SCREEN_RATIO);
    if (d.width > w || d.height > h) {
       setSize(width, height);
    } else setSize(d);
    */
    setSize(d);
    setPreferredSize(d);
    pack();
    container.addHierarchyBoundsListener(boundsAdapter);
}