Java Code Examples for javax.swing.JComponent.revalidate()

The following are Jave code examples for showing how to use revalidate() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: freecol   File: DefaultTransferHandler.java   View Source Code Vote up 6 votes
/**
 * Import a unit specified by its label to a component.
 *
 * @param comp The component to import to.
 * @param label The {@code UnitLabel} specifying the unit.
 * @param oldSelectedUnit A label for the old {@code Unit} to restore
 *     selection to.
 * @return True if the import succeeds.
 */
private boolean importUnit(JComponent comp, UnitLabel label,
                           UnitLabel oldSelectedUnit) {
    if (!(comp instanceof DropTarget)) return importFail(comp, "unit");
    final DropTarget target = (DropTarget)comp;

    // Check if the unit can be dragged to comp.
    final Unit unit = label.getUnit();
    if (!target.accepts(unit)) {
        return importFail(comp, "unacceptable unit (" + unit + ")");
    }

    // OK, add it.
    target.add(label, true);

    // Update unit selection.
    // New unit selection has already been taken care of
    // if this unit was moved to ToAmericaPanel
    restoreSelection(oldSelectedUnit);
    comp.revalidate();
    return true;
}
 
Example 2
Project: FreeCol   File: DefaultTransferHandler.java   View Source Code Vote up 6 votes
/**
 * Import a unit specified by its label to a component.
 *
 * @param comp The component to import to.
 * @param label The {@code UnitLabel} specifying the unit.
 * @param oldSelectedUnit A label for the old {@code Unit} to restore
 *     selection to.
 * @return True if the import succeeds.
 */
private boolean importUnit(JComponent comp, UnitLabel label,
                           UnitLabel oldSelectedUnit) {
    if (!(comp instanceof DropTarget)) return importFail(comp, "unit");
    final DropTarget target = (DropTarget)comp;

    // Check if the unit can be dragged to comp.
    final Unit unit = label.getUnit();
    if (!target.accepts(unit)) {
        return importFail(comp, "unacceptable unit (" + unit + ")");
    }

    // OK, add it.
    target.add(label, true);

    // Update unit selection.
    // New unit selection has already been taken care of
    // if this unit was moved to ToAmericaPanel
    restoreSelection(oldSelectedUnit);
    comp.revalidate();
    return true;
}
 
Example 3
Project: VASSAL-src   File: MenuScroller.java   View Source Code Vote up 5 votes
private void refreshMenu() {
  if (menuItems != null && menuItems.length > 0) {
    firstIndex = Math.max(topFixedCount, firstIndex);
    firstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, firstIndex);

    upItem.setEnabled(firstIndex > topFixedCount);
    downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount);

    menu.removeAll();
    for (int i = 0; i < topFixedCount; i++) {
      menu.add(menuItems[i]);
    }
    if (topFixedCount > 0) {
      menu.addSeparator();
    }

    menu.add(upItem);
    for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
      menu.add(menuItems[i]);
    }
    menu.add(downItem);

    if (bottomFixedCount > 0) {
      menu.addSeparator();
    }
    for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
      menu.add(menuItems[i]);
    }

    JComponent parent = (JComponent) upItem.getParent();
    parent.revalidate();
    parent.repaint();
  }
}
 
Example 4
Project: jaer   File: MenuScroller.java   View Source Code Vote up 5 votes
private void refreshMenu() {
  if (menuItems != null && menuItems.length > 0) {
    firstIndex = Math.max(topFixedCount, firstIndex);
    firstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, firstIndex);

    upItem.setEnabled(firstIndex > topFixedCount);
    downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount);

    menu.removeAll();
    for (int i = 0; i < topFixedCount; i++) {
      menu.add(menuItems[i]);
    }
    if (topFixedCount > 0) {
      menu.add(new JSeparator());
    }

    menu.add(upItem);
    for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
      menu.add(menuItems[i]);
    }
    menu.add(downItem);

    if (bottomFixedCount > 0) {
      menu.add(new JSeparator());
    }
    for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
      menu.add(menuItems[i]);
    }

    JComponent parent = (JComponent) upItem.getParent();
    parent.revalidate();
    parent.repaint();
  }
}
 
Example 5
Project: Cognizant-Intelligent-Test-Scripter   File: MenuScroller.java   View Source Code Vote up 5 votes
private void refreshMenu() {
    if (menuItems != null && menuItems.length > 0) {
        firstIndex = Math.max(topFixedCount, firstIndex);
        firstIndex = Math.min(menuItems.length - bottomFixedCount - scrollCount, firstIndex);

        upItem.setEnabled(firstIndex > topFixedCount);
        downItem.setEnabled(firstIndex + scrollCount < menuItems.length - bottomFixedCount);

        menu.removeAll();
        for (int i = 0; i < topFixedCount; i++) {
            menu.add(menuItems[i]);
        }
        if (topFixedCount > 0) {
            menu.addSeparator();
        }

        menu.add(upItem);
        for (int i = firstIndex; i < scrollCount + firstIndex; i++) {
            menu.add(menuItems[i]);
        }
        menu.add(downItem);

        if (bottomFixedCount > 0) {
            menu.addSeparator();
        }
        for (int i = menuItems.length - bottomFixedCount; i < menuItems.length; i++) {
            menu.add(menuItems[i]);
        }

        JComponent parent = (JComponent) upItem.getParent();
        parent.revalidate();
        parent.repaint();
    }
}
 
Example 6
Project: incubator-netbeans   File: PlatformsCustomizer.java   View Source Code Vote up 4 votes
private void selectPlatform (Node pNode) {
    Component active = null;
    for (Component c : cards.getComponents()) {
        if (c.isVisible() &&
            (c == jPanel1 || c == messageArea)) {
                active = c;
                break;
        }
    }
    final Dimension lastSize = active == null ?
        null :
        active.getSize();
    this.clientArea.removeAll();
    this.messageArea.removeAll();
    this.removeButton.setEnabled (false);
    if (pNode == null) {
        ((CardLayout)cards.getLayout()).last(cards);
        return;
    }
    JComponent target = messageArea;
    JComponent owner = messageArea;
    JavaPlatform platform = pNode.getLookup().lookup(JavaPlatform.class);
    if (pNode != getExplorerManager().getRootContext()) {
        if (platform != null) {
            this.removeButton.setEnabled (canRemove(platform, pNode.getLookup().lookup(DataObject.class)));
            if (!platform.getInstallFolders().isEmpty()) {
                this.platformName.setText(pNode.getDisplayName());
                for (FileObject installFolder : platform.getInstallFolders()) {
                    File file = FileUtil.toFile(installFolder);
                    if (file != null) {
                        this.platformHome.setText (file.getAbsolutePath());
                    }
                }
                target = clientArea;
                owner = jPanel1;
            }
        }
        Component component = null;
        if (pNode.hasCustomizer()) {
            component = pNode.getCustomizer();
        }
        if (component == null) {
            final PropertySheet sp = new PropertySheet();
            sp.setNodes(new Node[] {pNode});
            component = sp;
        }
        addComponent(target, component);
    }
    if (lastSize != null) {
        final Dimension newSize = owner.getPreferredSize();
        final Dimension updatedSize = new Dimension(
            Math.max(lastSize.width, newSize.width),
            Math.max(lastSize.height, newSize.height));
        if (!newSize.equals(updatedSize)) {
            owner.setPreferredSize(updatedSize);
        }
    }
    target.revalidate();
    CardLayout cl = (CardLayout) cards.getLayout();
    if (target == clientArea) {
        cl.first (cards);
    }
    else {
        cl.last (cards);
    }
}
 
Example 7
Project: incubator-netbeans   File: TabLayoutManager.java   View Source Code Vote up 4 votes
final void resizeContainer() {
    JComponent c = ( JComponent ) container.getParent();
    c.invalidate();
    c.revalidate();
    c.doLayout();
}
 
Example 8
Project: NBANDROID-V2   File: SdksCustomizer.java   View Source Code Vote up 4 votes
private void selectPlatform(Node pNode) {
    Component active = null;
    for (Component c : cards.getComponents()) {
        if (c.isVisible()
                && (c == jPanel1 || c == messageArea)) {
            active = c;
            break;
        }
    }
    final Dimension lastSize = active == null
            ? null
            : active.getSize();
    this.clientArea.removeAll();
    this.messageArea.removeAll();
    this.removeButton.setEnabled(false);
    if (pNode == null) {
        ((CardLayout) cards.getLayout()).last(cards);
        return;
    }
    JComponent target = messageArea;
    JComponent owner = messageArea;
    selectedPlatform = pNode.getLookup().lookup(AndroidSdk.class);
    if (pNode != getExplorerManager().getRootContext()) {
        if (selectedPlatform != null) {
            mkDefault.setEnabled(!selectedPlatform.isDefaultSdk());
            this.removeButton.setEnabled(!selectedPlatform.isDefaultSdk());
            if (!selectedPlatform.getInstallFolders().isEmpty()) {
                this.platformName.setText(pNode.getDisplayName());
                for (FileObject installFolder : selectedPlatform.getInstallFolders()) {
                    File file = FileUtil.toFile(installFolder);
                    if (file != null) {
                        this.platformHome.setText(file.getAbsolutePath());
                    }
                }
                target = clientArea;
                owner = jPanel1;
            }
        } else {
            removeButton.setEnabled(false);
            mkDefault.setEnabled(false);
        }
        Component component = null;
        if (pNode.hasCustomizer()) {
            component = pNode.getCustomizer();
        }
        if (component == null) {
            final PropertySheet sp = new PropertySheet();
            sp.setNodes(new Node[]{pNode});
            component = sp;
        }
        addComponent(target, component);
    }
    if (lastSize != null) {
        final Dimension newSize = owner.getPreferredSize();
        final Dimension updatedSize = new Dimension(
                Math.max(lastSize.width, newSize.width),
                Math.max(lastSize.height, newSize.height));
        if (!newSize.equals(updatedSize)) {
            owner.setPreferredSize(updatedSize);
        }
    }
    target.revalidate();
    CardLayout cl = (CardLayout) cards.getLayout();
    if (target == clientArea) {
        cl.first(cards);
    } else {
        cl.last(cards);
    }
}