下面列出了java.awt.Container#isVisible ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
@SuppressWarnings("deprecation")
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
@SuppressWarnings("deprecation")
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
private void enumerateCycle(Container container, List<Component> cycle) {
if (!(container.isVisible() && container.isDisplayable())) {
return;
}
cycle.add(container);
Component[] components = container.getComponents();
for (Component comp : components) {
if (comp instanceof Container) {
Container cont = (Container)comp;
if (!cont.isFocusCycleRoot() &&
!cont.isFocusTraversalPolicyProvider() &&
!((cont instanceof JComponent) && ((JComponent)cont).isManagingFocus()))
{
enumerateCycle(cont, cycle);
continue;
}
}
cycle.add(comp);
}
}
/**
* Positions the specified dialog at a position relative to its parent.
*
* @param dialog
* the dialog to be positioned.
* @param horizontalPercent
* the relative location.
* @param verticalPercent
* the relative location.
*/
public static void positionDialogRelativeToParent( final Dialog dialog, final double horizontalPercent,
final double verticalPercent ) {
final Container parent = dialog.getParent();
if ( parent == null || ( parent.isVisible() == false ) ) {
positionFrameOnScreen( dialog, horizontalPercent, verticalPercent );
return;
}
final Dimension d = dialog.getSize();
final Dimension p = parent.getSize();
final int baseX = parent.getX();
final int baseY = parent.getY();
final int parentPointX = baseX + (int) ( horizontalPercent * p.width );
final int parentPointY = baseY + (int) ( verticalPercent * p.height );
final int dialogPointX = Math.max( 0, parentPointX - (int) ( horizontalPercent * d.width ) );
final int dialogPointY = Math.max( 0, parentPointY - (int) ( verticalPercent * d.height ) );
// make sure the dialog fits completely on the screen...
final Rectangle s = parent.getGraphicsConfiguration().getBounds();
final Rectangle r = new Rectangle( dialogPointX, dialogPointY, d.width, d.height );
final Rectangle intersectedDialogBounds = r.intersection( s );
if ( intersectedDialogBounds.width < d.width ) {
r.x = s.width - d.width;
r.width = d.width;
}
if ( intersectedDialogBounds.height < d.height ) {
r.y = s.height - d.height;
r.height = d.height;
}
final Rectangle finalIntersection = r.intersection( s );
dialog.setBounds( finalIntersection );
}
/**
* Update only if visible to avoid opening the window just because
* the font setting changed.
*/
private void updateOnFontChange() {
Container top = this.getTopLevelAncestor();
if (top != null && top.isVisible()) {
update();
}
}
/**
* Prompts the user for input in a blocking internal dialog where
* the initial selection, possible selections, and all other
* options can be specified. The user will able to choose from
* <code>selectionValues</code>, where <code>null</code>
* implies the user can input
* whatever they wish, usually by means of a <code>JTextField</code>.
* <code>initialSelectionValue</code> is the initial value to prompt
* the user with. It is up to the UI to decide how best to represent
* the <code>selectionValues</code>, but usually a
* <code>JComboBox</code>, <code>JList</code>, or
* <code>JTextField</code> will be used.
*
* @param parentComponent the parent <code>Component</code> for the dialog
* @param message the <code>Object</code> to display
* @param title the <code>String</code> to display in the dialog
* title bar
* @param messageType the type of message to be displayed:
* <code>ERROR_MESSAGE</code>, <code>INFORMATION_MESSAGE</code>,
* <code>WARNING_MESSAGE</code>,
* <code>QUESTION_MESSAGE</code>, or <code>PLAIN_MESSAGE</code>
* @param icon the <code>Icon</code> image to display
* @param selectionValues an array of <code>Objects</code> that
* gives the possible selections
* @param initialSelectionValue the value used to initialize the input
* field
* @return user's input, or <code>null</code> meaning the user
* canceled the input
*/
public static Object showInternalInputDialog(Component parentComponent,
Object message, String title, int messageType, Icon icon,
Object[] selectionValues, Object initialSelectionValue) {
JOptionPane pane = new JOptionPane(message, messageType,
OK_CANCEL_OPTION, icon, null, null);
pane.putClientProperty(PopupFactory_FORCE_HEAVYWEIGHT_POPUP,
Boolean.TRUE);
Component fo = KeyboardFocusManager.getCurrentKeyboardFocusManager().
getFocusOwner();
pane.setWantsInput(true);
pane.setSelectionValues(selectionValues);
pane.setInitialSelectionValue(initialSelectionValue);
JInternalFrame dialog =
pane.createInternalFrame(parentComponent, title);
pane.selectInitialValue();
dialog.setVisible(true);
/* Since all input will be blocked until this dialog is dismissed,
* make sure its parent containers are visible first (this component
* is tested below). This is necessary for JApplets, because
* because an applet normally isn't made visible until after its
* start() method returns -- if this method is called from start(),
* the applet will appear to hang while an invisible modal frame
* waits for input.
*/
if (dialog.isVisible() && !dialog.isShowing()) {
Container parent = dialog.getParent();
while (parent != null) {
if (parent.isVisible() == false) {
parent.setVisible(true);
}
parent = parent.getParent();
}
}
AWTAccessor.getContainerAccessor().startLWModal(dialog);
if (parentComponent instanceof JInternalFrame) {
try {
((JInternalFrame)parentComponent).setSelected(true);
} catch (java.beans.PropertyVetoException e) {
}
}
if (fo != null && fo.isShowing()) {
fo.requestFocus();
}
Object value = pane.getInputValue();
if (value == UNINITIALIZED_VALUE) {
return null;
}
return value;
}
private Map<Component, Rectangle> createBlueprint(Container parent) {
CellLayout masterLayout;
if (group.contains(parent)) {
masterLayout = new CellLayout();
for (Container container : group) {
if (container.isVisible()) {
CellLayout cellLayout = getCellLayout(container);
masterLayout.add(cellLayout);
}
}
} else {
masterLayout = getCellLayout(parent);
}
int x = 0;
int y = 0;
if (parent instanceof JComponent) {
Border b = ((JComponent) parent).getBorder();
if (b != null) {
Insets i = b.getBorderInsets(parent);
x = i.left;
y = i.top;
}
}
List<List<Component>> grid = createGrid(parent);
Map<Component, Rectangle> returnValue = new HashMap<>();
int y0 = y;
for (int row = 0; row < grid.size(); row++) {
int x0 = x;
for (int column = 0; column < grid.get(row).size(); column++) {
Component c = grid.get(row).get(column);
Dimension d = c.getPreferredSize();
Rectangle r = new Rectangle(x0, y0, d.width, d.height);
// masterLayout.columnWidths[column],
// masterLayout.rowHeights[row]);
returnValue.put(c, r);
x0 += masterLayout.columnWidths[column];
x0 += horizontalPadding;
}
y0 += masterLayout.rowHeights[row];
y0 += verticalPadding;
}
return returnValue;
}
public static void startModal(javax.swing.JInternalFrame f) {
synchronized(f) {
/* Since all input will be blocked until this dialog is dismissed,
* make sure its parent containers are visible first (this component
* is tested below). This is necessary for JApplets, because
* because an applet normally isn't made visible until after its
* start() method returns -- if this method is called from start(),
* the applet will appear to hang while an invisible modal frame
* waits for input.
*/
if (f.isVisible() && !f.isShowing()) {
Container parent = f.getParent();
while (parent != null) {
if (parent.isVisible() == false) {
parent.setVisible(true);
}
parent = parent.getParent();
}
}
try {
if (SwingUtilities.isEventDispatchThread()) {
EventQueue theQueue = f.getToolkit().getSystemEventQueue();
while (f.isVisible()) {
// This is essentially the body of EventDispatchThread
AWTEvent event = theQueue.getNextEvent();
Object src = event.getSource();
// can't call theQueue.dispatchEvent, so I pasted it's body here
/*if (event instanceof ActiveEvent) {
((ActiveEvent) event).dispatch();
} else */ if (src instanceof Component) {
((Component) src).dispatchEvent(event);
} else if (src instanceof MenuComponent) {
((MenuComponent) src).dispatchEvent(event);
} else {
System.err.println("unable to dispatch event: " + event);
}
}
} else
while (f.isVisible())
f.wait();
} catch(InterruptedException e){}
}
}