Java Code Examples for java.awt.Component#invalidate()

The following examples show how to use java.awt.Component#invalidate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClosableTabbedPane.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Remove the closing button for the provided tab index.
 *
 * @param tabIndex index of tab in tabbed pane
 */
public void removeClosingButton (int tabIndex)
{
    Component tab = getTabComponentAt(tabIndex);

    if (tab instanceof ButtonTabComponent) {
        for (Component c : ((Container) tab).getComponents()) {
            if (c instanceof JButton) {
                ((Container) tab).remove(c);
                tab.invalidate();
                tab.repaint();

                return;
            }
        }
    }
}
 
Example 2
Source File: DropdownButton.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setText(String text) {
    if (button != null) {
        String _text = button.getText();
        button.setText(text);
        
        Component parent = getParent();
        if (!Objects.equals(text, _text) && parent != null) {
            parent.invalidate();
            parent.revalidate();
            parent.repaint();
        }
    }
}
 
Example 3
Source File: DropdownButton.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void setIcon(Icon icon) {
    if (button != null) {
        Icon _icon = button.getIcon();
        button.setIcon(icon);
        
        Component parent = getParent();
        if (!Objects.equals(icon, _icon) && parent != null) {
            parent.invalidate();
            parent.revalidate();
            parent.repaint();
        }
    }
}
 
Example 4
Source File: BaseWindow.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Invalidates the specified component and all of its children, recursively.
 *
 * @param comp The root component to start with.
 */
public void invalidate(Component comp) {
    comp.invalidate();
    comp.repaint();
    if (comp instanceof Container) {
        for (Component child : ((Container) comp).getComponents()) {
            invalidate(child);
        }
    }
}
 
Example 5
Source File: DropdownButton.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void setText(String text) {
    if (button != null) {
        String _text = button.getText();
        button.setText(text);
        
        Component parent = getParent();
        if (!Objects.equals(text, _text) && parent != null) {
            parent.invalidate();
            parent.revalidate();
            parent.repaint();
        }
    }
}
 
Example 6
Source File: DropdownButton.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public void setIcon(Icon icon) {
    if (button != null) {
        Icon _icon = button.getIcon();
        button.setIcon(icon);
        
        Component parent = getParent();
        if (!Objects.equals(icon, _icon) && parent != null) {
            parent.invalidate();
            parent.revalidate();
            parent.repaint();
        }
    }
}
 
Example 7
Source File: TranslucentPopup.java    From littleluck with Apache License 2.0 5 votes vote down vote up
TranslucentPopup(Component owner, Component contents, int ownerX, int ownerY) 
{ 
    this.popupWindow = new JWindow();
    popupWindow.setBackground(UIManager.getColor(LuckGlobalBundle.TRANSLUCENT_COLOR));
    popupWindow.setLocation(ownerX, ownerY); 
    popupWindow.getContentPane().add(contents, BorderLayout.CENTER); 
    contents.invalidate(); 
}
 
Example 8
Source File: LayoutControlPanel.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    JRadioButton rb = (JRadioButton) e.getSource();
    if(!rb.isSelected()) {
               return;
           }
           String cmd = rb.getActionCommand();
           int hPos, vPos;
           if(cmd.equals("NW")) {
                   hPos = LEFT; vPos = TOP;
           } else if(cmd.equals("N")) {
                   hPos = CENTER; vPos = TOP;
           } else if(cmd.equals("NE")) {
                   hPos = RIGHT; vPos = TOP;
           } else if(cmd.equals("W")) {
                   hPos = LEFT; vPos = CENTER;
           } else if(cmd.equals("C")) {
                   hPos = CENTER; vPos = CENTER;
           } else if(cmd.equals("E")) {
                   hPos = RIGHT; vPos = CENTER;
           } else if(cmd.equals("SW")) {
                   hPos = LEFT; vPos = BOTTOM;
           } else if(cmd.equals("S")) {
                   hPos = CENTER; vPos = BOTTOM;
           } else /*if(cmd.equals("SE"))*/ {
                   hPos = RIGHT; vPos = BOTTOM;
           }
           for(int i = 0; i < demo.getCurrentControls().size(); i++) {
               Component c = (Component) demo.getCurrentControls().elementAt(i);
               setAlignment(c,hPos,vPos);
               c.invalidate();
           }
           demo.invalidate();
           demo.validate();
           demo.repaint();
}
 
Example 9
Source File: PropertyPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Installs the component we will embed to display the property */
private void installDisplayerComponent() {
    //Fetch or instantiate the component we will embed to display the 
    //property.  Depending on the prefs, it may be a RendererPropertyDisplayer,
    //an EditablePropertyDisplayer or a CustomPropertyDisplayer.
    PropertyDisplayer displayer = getPropertyDisplayer();

    //Find who has focus now, so if we have focus, focus won't end up set
    //to null
    Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();

    boolean hadFocus = (focusOwner == this) || isAncestorOf(focusOwner);

    if (hadFocus) {
        //If we had focus, clear the global focus owner for now, so that
        //when the existing component is removed, it does not cause
        //focus to get briefly set to a random component
        KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
    }

    //Fetch the new inner component (the custom editor or Inplace editor)
    Component newInner = displayer.getComponent();

    //Set the enabled state appropriately.  For implementations of 
    //PropertyDisplayer_Editable, this will already be handled; for render-
    //only cases, it should be handled explicitly
    if (!(displayer instanceof PropertyDisplayer_Editable)) {
        //only for renderers
        newInner.setEnabled(isEnabled() && getProperty().canWrite());
    }

    newInner.setForeground(getForeground());
    newInner.setBackground(getBackground());

    //Make sure the inner component has really changed
    if (newInner != inner) {
        synchronized (getTreeLock()) {
            //remove the odl component
            if (inner != null) {
                remove(inner);
            }

            //and add the new one (if any)
            if (newInner != null) {
                add(newInner);

                //invalidate its layout so it will be re-laid out
                newInner.invalidate();
                inner = newInner;
            }
        }
    }

    //Force a re-layout immediately if visible
    if (isShowing() && !(getParent() instanceof javax.swing.CellRendererPane)) {
        validate();
    }

    //Restore focus if necessary
    if (hadFocus && isEnabled() && ((preferences & PREF_READ_ONLY) == 0)) {
        requestFocus();
    }

    //Simply adding a component to a container can sometimes cause it to be
    //given focus even though it's not focusable.  If this has happened,
    //find the next component in the focus cycle root and force focus to that.
    //Mainly a problem with JFileChooser, but we also have a few property
    //editors that force focus on addNotify which should be fixed
    if (!isEnabled() || ((preferences & PREF_READ_ONLY) != 0)) {
        Component focus = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();

        if ((focus == inner) || ((inner instanceof Container) && ((Container) inner).isAncestorOf(focus))) {
            this.transferFocusUpCycle();
        }
    }
}
 
Example 10
Source File: SizeSaver.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void attach(Component _comp) {
  if(this.comp != null) {
    throw new IllegalStateException("SizeSaver can only be attach to one compoent. current component is " + this.comp);
  }
  this.comp = _comp;

  Dimension size = getSize();

  if(size != null) {
    // System.out.println("attach " + id + " size=" + size);
    comp.setSize(size);
    if(comp instanceof JComponent) {
      ((JComponent)comp).setPreferredSize(size);
    }
  }

  Preferences prefs = getPrefs();

  if(comp instanceof JFrame) {
    Toolkit tk = comp.getToolkit();
    if(tk.isFrameStateSupported(Frame.MAXIMIZED_VERT) ||
       tk.isFrameStateSupported(Frame.MAXIMIZED_HORIZ) ||
       tk.isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
      int state = prefs.getInt(KEY_STATE, Frame.NORMAL);
      ((Frame)comp).setExtendedState(state);
    }
    int x = prefs.getInt(KEY_X, 0);
    int y = prefs.getInt(KEY_Y, 0);
    // System.out.println("attach " + id + " pos=" + x + ", " + y);
    comp.setLocation(x, y);
  }

  if(comp instanceof JSplitPane) {
    JSplitPane split = (JSplitPane)comp;
    int pos = prefs.getInt(KEY_SPLITPOS, defSplit);
    if(pos != -1) {
      // System.out.println("attach " + id + " split=" + pos);
      split.setDividerLocation(pos);
      // Tell components that they may want to redo its layout
      Component parent = split.getParent();
      if (null!=parent) {
        parent.invalidate();
      } else {
        split.invalidate();
      }
    }

    splitListener = new ComponentAdapter() {
        public void 	componentResized(ComponentEvent e) {
          store();
        }
        public void 	componentMoved(ComponentEvent e) {
          store();
        }
      };

    split.getLeftComponent().addComponentListener(splitListener);
  }

  this.comp.addComponentListener(this);
}