下面列出了javax.swing.JComponent#isShowing ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void hierarchyChanged(HierarchyEvent event) {
if ((event.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0) {
JComponent component = (JComponent)event.getComponent();
final Demo demo = (Demo)component.getClientProperty("swingset3.demo");
if (!component.isShowing()) {
demo.stop();
} else {
demoContainer.revalidate();
EventQueue.invokeLater(new Runnable() {
public void run() {
demo.start();
}
});
}
}
}
/**
* Creates a bubble for the component and kills other bubbles.
*
* @param component
* the component for which to show the bubble
* @param style
* the bubble style
* @param i18n
* the i18n key
* @param arguments
* arguments for the i18n
*/
private void createBubbleWindow(JComponent component, BubbleStyle style, String i18n, Object... arguments) {
// BubbleWindow requires a visible owner
if (!component.isShowing()) {
return;
}
killCurrentBubbleWindow(null);
bubbleOwner = component;
JButton okayButton = new JButton(I18N.getGUILabel("io.dataimport.step.excel.sheet_selection.got_it"));
final ComponentBubbleWindow errorWindow = new ComponentBubbleWindow(component, style,
SwingUtilities.getWindowAncestor(ExcelSheetSelectionPanel.this), AlignedSide.TOP, i18n, null, null, false,
true, new JButton[] { okayButton }, arguments);
okayButton.addActionListener(e -> errorWindow.killBubble(false));
// show and remember error window
errorWindow.setVisible(true);
currentBubbleWindow = errorWindow;
}
@Override
public void valueChanged(long bid)
{
boolean bHasVisibleComponent = false;
synchronized (components) {
for (final JComponent comp : components) {
if (comp.isShowing()) {
bHasVisibleComponent = true;
break;
}
}
}
lastBID = bid;
if (bHasVisibleComponent) {
valueChangedLazy(bid);
}
}
@Override
public void valueChanged(long bid)
{
boolean bHasVisibleComponent = false;
synchronized (components) {
for (final JComponent comp : components) {
if (comp.isShowing()) {
bHasVisibleComponent = true;
break;
}
}
}
lastBID = bid;
if (bHasVisibleComponent) {
valueChangedLazy(bid);
}
}
@Override
public void valueChanged(long bid)
{
boolean bHasVisible = false;
for (final JComponent comp : components) {
if (comp.isShowing()) {
bHasVisible = true;
break;
}
}
lastBID = bid;
if (bHasVisible) {
valueChangedLazy(bid);
}
}
public void hierarchyChanged(HierarchyEvent event) {
if ((event.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0) {
JComponent component = (JComponent)event.getComponent();
final Demo demo = (Demo)component.getClientProperty("swingset3.demo");
if (!component.isShowing()) {
demo.stop();
} else {
demoContainer.revalidate();
EventQueue.invokeLater(new Runnable() {
public void run() {
demo.start();
}
});
}
}
}
private void waitForComponentToBeHidden(JComponent component) {
int numWaits = 0;
int sleepyTime = 100;
int maxWaits = 20;
while (component.isShowing() && maxWaits > numWaits++) {
sleep(sleepyTime);
}
if (numWaits >= maxWaits) {
Assert.fail("Component not hidden!");
}
}
private void assertVisible(String msg, JComponent tc) throws InterruptedException {
int cnt = 0;
while (!tc.isShowing()) {
Thread.sleep(100);
if (cnt++ > 10) {
break;
}
}
assertTrue(msg + ". Showing", tc.isShowing());
}
/**
* Calculate whether a popover should be visible or not.
* <p>
* The default implementation takes into account the keybord focus, mouse
* position, and expanded state.
*
* @param popover
* the JPopover to evaluate
* @return true if the popover should be visible.
*/
@Override
public boolean isVisible(JPopover<T> popover) {
JComponent owner = popover.getOwner();
JComponent contents = popover.getContents();
boolean newVisible;
if (owner.isShowing() && owner.isEnabled()) {
newVisible = isFocusOwnerOrAncestor(owner) || isRollover(owner);
if (!newVisible && popover.isRolloverContents()) {
newVisible = isFocusOwnerOrAncestor(contents)
|| (isRollover(contents));
}
} else {
newVisible = false;
}
if (isExpanded(owner)) {
newVisible = false;
}
if (isInsideActiveWindow(owner) == false
&& isInsideActiveWindow(contents) == false)
newVisible = false;
return newVisible;
}
/**
* Return true if the mouse is currently over the argument.
*/
protected boolean isRollover(JComponent jc) {
if (!jc.isShowing())
return false;
Point p = jc.getLocationOnScreen();
int w = jc.getWidth();
int h = jc.getHeight();
Point mouse = MouseInfo.getPointerInfo().getLocation();
return mouse.x >= p.x && mouse.y >= p.y && mouse.x < p.x + w
&& mouse.y < p.y + h;
}
private void checkThreadViolations(JComponent c) {
if (!SwingUtilities.isEventDispatchThread() && (completeCheck || c.isShowing())) {
boolean repaint = false;
boolean fromSwing = false;
boolean imageUpdate = false;
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (StackTraceElement st : stackTrace) {
if (repaint && st.getClassName().startsWith("javax.swing.") &&
// for details see
// https://swinghelper.dev.java.net/issues/show_bug.cgi?id=1
!st.getClassName().startsWith("javax.swing.SwingWorker")) {
fromSwing = true;
}
if (repaint && "imageUpdate".equals(st.getMethodName())) {
imageUpdate = true;
}
if ("repaint".equals(st.getMethodName())) {
repaint = true;
fromSwing = false;
}
}
if (imageUpdate) {
//assuming it is java.awt.image.ImageObserver.imageUpdate(...)
//image was asynchronously updated, that's ok
return;
}
if (repaint && !fromSwing) {
//no problems here, since repaint() is thread safe
return;
}
//ignore the last processed component
if (lastComponent != null && c == lastComponent.get()) {
return;
}
lastComponent = new WeakReference<JComponent>(c);
violationFound(c, stackTrace);
}
}
private static boolean isShown(JComponent field) {
return field.isVisible() && field.isShowing();
}
protected void recalculateHighlight(boolean forceImmediateUpdate) {
Rectangle highlightSum = null;
for (JComponent h : highlightedComponents) {
if (h.isShowing() && h.getParent() != null) {
Rectangle r = h.getBounds();
r = SwingUtilities.convertRectangle(h.getParent(), r, this);
if (highlightSum == null) {
highlightSum = r;
} else {
highlightSum.add(r);
}
}
}
if (highlightSum == null) {
putClientProperty(TARGET_ALPHA, 0f);
} else {
putClientProperty(TARGET_ALPHA, 1f);
putClientProperty(TARGET_X, (float) highlightSum.getX());
putClientProperty(TARGET_Y, (float) highlightSum.getY());
putClientProperty(TARGET_WIDTH, (float) highlightSum.getWidth());
putClientProperty(TARGET_HEIGHT, (float) highlightSum.getHeight());
}
if (getClientProperty(REAL_X) == null) {
putClientProperty(REAL_ALPHA, 0);
putClientProperty(REAL_X, getClientProperty(TARGET_X));
putClientProperty(REAL_Y, getClientProperty(TARGET_Y));
putClientProperty(REAL_WIDTH, getClientProperty(TARGET_WIDTH));
putClientProperty(REAL_HEIGHT, getClientProperty(TARGET_HEIGHT));
}
if (forceImmediateUpdate) {
putClientProperty(REAL_ALPHA, getClientProperty(TARGET_ALPHA));
putClientProperty(REAL_X, getClientProperty(TARGET_X));
putClientProperty(REAL_Y, getClientProperty(TARGET_Y));
putClientProperty(REAL_WIDTH, getClientProperty(TARGET_WIDTH));
putClientProperty(REAL_HEIGHT, getClientProperty(TARGET_HEIGHT));
}
}