protected static JFrame findJFrame (Component component) { Container parent = component.getParent(); while (parent != null) { if (parent instanceof JFrame) { return (JFrame)parent; } parent = parent.getParent(); } return null; }
protected static JFrame findJFrame (Component component) { Container parent = component.getParent(); while (parent != null) { if (parent instanceof JFrame) { return (JFrame)parent; } parent = parent.getParent(); } return null; }
/** Finds the JViewport enclosing this component. */ private JViewport getViewport() { Container p = getParent(); if (p instanceof JViewport) { Container gp = p.getParent(); if (gp instanceof JScrollPane) { JScrollPane scroller = (JScrollPane) gp; JViewport viewport = scroller.getViewport(); if (viewport == null || viewport.getView() != this) { return null; } else { return viewport; } } } return null; }
private void positionPanel() { if (parent == null) return; Container scroll = SwingUtilities.getAncestorOfClass(JScrollPane.class, parent); int height = (int)getPreferredSize().getHeight(); if (scroll != null) { Rectangle bounds = scroll.getBounds(); bounds.translate(0, scroll.getHeight() - height); bounds.height = height; Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(), oldGlass); bounds.setLocation(pos); setBounds(bounds); repaint(); } }
bounds.height = height; final JRootPane rootPane = SwingUtilities.getRootPane(myParent); final Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(), rootPane); final Window window = SwingUtilities.getWindowAncestor(myParent); final Point windowPos = window.getLocation();
private void positionPanel() { final JComponent contentComponent = myEditor.getContentComponent(); Container scroll = SwingUtilities.getAncestorOfClass(JScrollPane.class, contentComponent); setSize(scroll.getSize()); myLineHeight = myText.getFontMetrics(myText.getFont()).getHeight(); int count = countLines(myText.getText()); int visLines = getSize().height / myLineHeight - 1; int lines = Math.min(count, visLines); setSize(getSize().width, lines * myLineHeight + myLabel.getPreferredSize().height + getBorder().getBorderInsets(this).top * 2); int height = getSize().height; Rectangle bounds = scroll.getBounds(); bounds.translate(0, scroll.getHeight() - height); bounds.height = height; Point pos = SwingUtilities.convertPoint(scroll.getParent(), bounds.getLocation(), SwingUtilities.getRootPane(contentComponent).getGlassPane()); bounds.setLocation(pos); setBounds(bounds); myScrollPane.getVerticalScrollBar().setValue(0); if (!Options.getInstance().isSet("more")) { // FIX scrollOffset(100000); } else { scrollOffset(0); } }
private JButton btnExit; ... btnExit = new JButton("Quit"); btnExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ Container frame = btnExit.getParent(); do frame = frame.getParent(); while (!(frame instanceof JFrame)); ((JFrame) frame).dispose(); } });
private Window parentWindow(final Container window) { if (window instanceof Window) { return (Window) window; } return parentWindow(window.getParent()); } }
class SomeSpecialComponent extends JComponent implements HierarchyListener { private boolean amIVisible() { Container c = getParent(); while (c != null) if (!c.isVisible()) return false; else c = c.getParent(); return true; } public void addNotify() { super.addNotify(); addHierarchyListener(this); } public void removeNotify() { removeHierarchyListener(this); super.removeNotify(); } public void hierarchyChanged(HierarchyEvent e) { System.out.println("Am I visible? " + amIVisible()); } }
/** * Returns the gutter component of the scroll pane containing a text * area, if any. * * @param textArea The text area. * @return The gutter, or <code>null</code> if the text area is not in * an {@link RTextScrollPane}. * @see RTextScrollPane#getGutter() */ public static Gutter getGutter(RTextArea textArea) { Gutter gutter = null; Container parent = textArea.getParent(); if (parent instanceof JViewport) { parent = parent.getParent(); if (parent instanceof RTextScrollPane) { RTextScrollPane sp = (RTextScrollPane)parent; gutter = sp.getGutter(); // Should always be non-null } } return gutter; }
private void breakFocusCycle() { Container o = getParent(); while (o != null) { if (o != null && o.isFocusable()) break; o = o.getParent(); } if (o != null) o.requestFocus(); }
@Override public void actionPerformed(ActionEvent e){ if ( count <= repeatCount){ int x = (int) tfuncx.getValue(count); int y = (int) tfuncy.getValue(count); count++; Rectangle r1 = comp.getBounds(); comp.setActualLocation(x,y); Rectangle r2 = comp.getBounds(); r1.add(r2); Container c = comp.getParent(); if (c != null){ c.getParent().getParent().repaint(r1.x,r1.y,r1.width,r1.height); } }else{ timer.stop(); } }
@Override public void actionPerformed(ActionEvent e) { float r = funcr.getValue(count); int x = (int) (origin.x + (int) radius * Math.sin(r)); int y= (int) (origin.y + (int) radius * Math.cos(r)); Point p = new Point(x,y); Rectangle r1 = comp.getBounds(); comp.setLocation(p); // r1 stores the union of the bounds before/after the animated step Rectangle r2 = comp.getBounds(); r1.add(r2); comp.getParent().getParent().repaint(r1.x,r1.y,r1.width,r1.height); //repaint(r1); // comp.getParent().invalidate(); // comp.repaint(); if (count == repeatCount) count = 0; else count++; } }
for (Container p = contents.getParent() ; p != null ; p = p.getParent()) { if (p instanceof JWindow || p instanceof Panel) {
public void close() { Container parent = getParent(); if (!(parent instanceof JSplitPane)) return; JSplitPane split = (JSplitPane) parent; Component firstComponent = split.getTopComponent(); Component secondComponent = split.getBottomComponent(); Component remainingComponent = firstComponent == this ? secondComponent : firstComponent; split.setTopComponent(null); split.setBottomComponent(null); Container grandParent = parent.getParent(); if (grandParent instanceof JSplitPane) { JSplitPane grandSplit = (JSplitPane) grandParent; // Remove the split pane. if (split == grandSplit.getTopComponent()) { grandSplit.setTopComponent(remainingComponent); } else { grandSplit.setBottomComponent(remainingComponent); } } else { grandParent.remove(parent); grandParent.add(remainingComponent); } grandParent.validate(); }
boolean isCaretAtEnd = this.getProxy().getCaretPosition() == this.getProxy().getDocument().getLength(); JScrollPane v = (JScrollPane) this.getProxy().getParent().getParent(); JScrollBar vertical = v.getVerticalScrollBar(); int extent = vertical.getModel().getExtent();
public static void setRegExError(String error, JTextPane jTextPane, final Font textFont, final BackgroundColor validTextFieldBackground, final BackgroundColor warningTextFieldBackground) { HtmlBuilder html = new HtmlBuilder(); html.tag("html").style("margin:2px;vertical-align:middle;").attr(validTextFieldBackground, textFont).tag("body"); html.attr(warningTextFieldBackground).tag("div"); html.append(toHtmlError(error, true)); html.closeTag("div"); html.closeTag("body"); html.closeTag("html"); jTextPane.setVisible(true); jTextPane.setText(html.toFinalizedString()); jTextPane.revalidate(); jTextPane.getParent().revalidate(); jTextPane.getParent().getParent().revalidate(); }
private static JDialog findContainingDialog(JComponent component) { Container container = component.getParent(); while (container != null) { if (container instanceof JDialog) { return (JDialog) container; } container = container.getParent(); } return null; }
private static JFrame findContainingFrame(JComponent component) { Container container = component.getParent(); while (container != null) { if (container instanceof JFrame) { return (JFrame) container; } container = container.getParent(); } return null; }