本文整理汇总了Java中java.awt.Component.invalidate方法的典型用法代码示例。如果您正苦于以下问题:Java Component.invalidate方法的具体用法?Java Component.invalidate怎么用?Java Component.invalidate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Component
的用法示例。
在下文中一共展示了Component.invalidate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setText
import java.awt.Component; //导入方法依赖的package包/类
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();
}
}
}
示例2: setIcon
import java.awt.Component; //导入方法依赖的package包/类
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();
}
}
}
示例3: installDisplayerComponent
import java.awt.Component; //导入方法依赖的package包/类
/** 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();
}
}
}