Java Code Examples for java.awt.Component#setLocation()
The following examples show how to use
java.awt.Component#setLocation() .
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: SlideContainer.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 6 votes |
@Override public Component add(Component comp) { setsize(comp.getPreferredSize()); Component[] comps = getComponents(); if (comps.length > 0) { oldComponent = comps[0]; } if (comp.equals(oldComponent)) { return super.add(comp); } if (oldComponent != null) { putLayer((JComponent) oldComponent, JLayeredPane.DEFAULT_LAYER); } Component returnResult = super.add(comp); putLayer((JComponent) comp, JLayeredPane.DRAG_LAYER); comp.setSize(getPreferredSize()); comp.setVisible(true); comp.setLocation(0, 0 - getPreferredSize().height); slideFromTop(comp, oldComponent); return returnResult; }
Example 2
Source File: GuiHelper.java From binnavi with Apache License 2.0 | 6 votes |
/** Centers the child component relative to its parent component. */ public static final void centerChildToParent( final Component parent, final Component child, final boolean bStayOnScreen) { int x = (parent.getX() + (parent.getWidth() / 2)) - (child.getWidth() / 2); int y = (parent.getY() + (parent.getHeight() / 2)) - (child.getHeight() / 2); if (bStayOnScreen) { final Toolkit tk = Toolkit.getDefaultToolkit(); final Dimension ss = new Dimension(tk.getScreenSize()); if ((x + child.getWidth()) > ss.getWidth()) { x = (int) (ss.getWidth() - child.getWidth()); } if ((y + child.getHeight()) > ss.getHeight()) { y = (int) (ss.getHeight() - child.getHeight()); } if (x < 0) { x = 0; } if (y < 0) { y = 0; } } child.setLocation(x, y); }
Example 3
Source File: FaceBrowser.java From Face-Recognition with GNU General Public License v3.0 | 6 votes |
@Override public void doLayout() { // TODO Auto-generated method stub super.doLayout(); Component[] components = this.getComponents(); int cury = 0; for (Component c : components) { c.setLocation(0, cury); c.setSize(this.getWidth(), c.getHeight()); cury += c.getHeight(); } height = cury; this.revalidate(); }
Example 4
Source File: TableLayout.java From gdx-texture-packer-gui with Apache License 2.0 | 6 votes |
public void layout () { Table table = getTable(); Insets insets = table.getInsets(); super.layout(insets.left, insets.top, // table.getWidth() - insets.left - insets.right, // table.getHeight() - insets.top - insets.bottom); List<Cell> cells = getCells(); for (int i = 0, n = cells.size(); i < n; i++) { Cell c = cells.get(i); if (c.getIgnore()) continue; Component component = (Component)c.getWidget(); component.setLocation((int)c.getWidgetX(), (int)c.getWidgetY()); component.setSize((int)c.getWidgetWidth(), (int)c.getWidgetHeight()); } if (getDebug() != Debug.none) SwingToolkit.startDebugTimer(); }
Example 5
Source File: VerticalFlowLayout.java From xyTalk-pc with GNU Affero General Public License v3.0 | 6 votes |
/** * places the components defined by first to last within the target * container using the bounds box defined. * * @param target the container. * @param x the x coordinate of the area. * @param y the y coordinate of the area. * @param width the width of the area. * @param height the height of the area. * @param first the first component of the container to place. * @param last the last component of the container to place. */ private void placethem(Container target, int x, int y, int width, int height, int first, int last) { int align = getAlignment(); if (align == MIDDLE) y += height / 2; if (align == BOTTOM) y += height; for (int i = first; i < last; i++) { Component m = target.getComponent(i); Dimension md = m.getSize(); if (m.isVisible()) { int px = x + (width - md.width) / 2; m.setLocation(px, y); y += vgap + md.height; } } }
Example 6
Source File: TableLayout.java From object-recognition-tensorflow with Apache License 2.0 | 6 votes |
public void layout () { Table table = getTable(); Insets insets = table.getInsets(); super.layout(insets.left, insets.top, // table.getWidth() - insets.left - insets.right, // table.getHeight() - insets.top - insets.bottom); List<Cell> cells = getCells(); for (int i = 0, n = cells.size(); i < n; i++) { Cell c = cells.get(i); if (c.getIgnore()) continue; Component component = (Component)c.getWidget(); component.setLocation((int)c.getWidgetX(), (int)c.getWidgetY()); component.setSize((int)c.getWidgetWidth(), (int)c.getWidgetHeight()); } if (getDebug() != Debug.none) SwingToolkit.startDebugTimer(); }
Example 7
Source File: GuiHelper.java From binnavi with Apache License 2.0 | 6 votes |
/** * Centers the child component relative to it's parent component * * @param parent * @param child * @param bStayOnScreen */ public static final void centerChildToParent(final Component parent, final Component child, final boolean bStayOnScreen) { int x = (parent.getX() + (parent.getWidth() / 2)) - (child.getWidth() / 2); int y = (parent.getY() + (parent.getHeight() / 2)) - (child.getHeight() / 2); if (bStayOnScreen) { final Toolkit tk = Toolkit.getDefaultToolkit(); final Dimension ss = new Dimension(tk.getScreenSize()); if ((x + child.getWidth()) > ss.getWidth()) { x = (int) (ss.getWidth() - child.getWidth()); } if ((y + child.getHeight()) > ss.getHeight()) { y = (int) (ss.getHeight() - child.getHeight()); } if (x < 0) { x = 0; } if (y < 0) { y = 0; } } child.setLocation(x, y); }
Example 8
Source File: TableLayout.java From tablelayout with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void layout () { Table table = getTable(); Insets insets = table.getInsets(); super.layout(insets.left, insets.top, // table.getWidth() - insets.left - insets.right, // table.getHeight() - insets.top - insets.bottom); List<Cell> cells = getCells(); for (int i = 0, n = cells.size(); i < n; i++) { Cell c = cells.get(i); if (c.getIgnore()) continue; Component component = (Component)c.getWidget(); component.setLocation((int)c.getWidgetX(), (int)c.getWidgetY()); component.setSize((int)c.getWidgetWidth(), (int)c.getWidgetHeight()); } if (getDebug() != Debug.none) SwingToolkit.startDebugTimer(); }
Example 9
Source File: GuiUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Set the location of a component to center it on the screen. * * @param component * the component to center. */ public static void centerOnScreen( Component component ) { Dimension prefSize = component.getPreferredSize(); Dimension parentSize; java.awt.Point parentLocation = new java.awt.Point(0, 0); parentSize = Toolkit.getDefaultToolkit().getScreenSize(); int x = parentLocation.x + (parentSize.width - prefSize.width) / 2; int y = parentLocation.y + (parentSize.height - prefSize.height) / 2; component.setLocation(x, y); }
Example 10
Source File: WrappingLayout.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
private int moveComponents(Container parent, int x, int y, int width, int height, int rowStart, int rowEnd, boolean ltr) { switch (align) { case LEFT: x += ltr ? 0 : width; break; case CENTER: x += width / 2; break; case RIGHT: x += ltr ? width : 0; break; case LEADING: break; case TRAILING: x += width; break; } for (int i = rowStart; i < rowEnd; i++) { Component c = parent.getComponent(i); if (c.isVisible()) { int cy; cy = y + (height - c.getHeight()) / 2; if (ltr) { c.setLocation(x, cy); } else { c.setLocation(parent.getWidth() - x - c.getWidth(), cy); } x += c.getWidth() + hgap; } } return height; }
Example 11
Source File: MetalworksPrefs.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void layoutContainer(Container c) { Insets insets = c.getInsets(); int height = yInset + insets.top; Component[] children = c.getComponents(); Dimension compSize = null; for (Component child : children) { compSize = child.getPreferredSize(); child.setSize(compSize.width, compSize.height); child.setLocation(xInset + insets.left, height); height += compSize.height + yGap; } }
Example 12
Source File: GraphPanelEditor.java From pdfxtk with Apache License 2.0 | 5 votes |
private void properties(GraphNode node) { Component props = (Component)node.get(gp.NODE_PROPERTIES); if(props != null) { Component c = (Component)node.get(gp.COMPONENT); Point loc = Awt.place(props.getBounds(), c.getX() + c.getWidth() / 2, c.getY() + c.getHeight(), getBounds()); loc.x += getLocationOnScreen().x; loc.y += getLocationOnScreen().y; props.setLocation(loc); props.setVisible(true); gp.repaint(); } }
Example 13
Source File: GridView.java From swift-k with Apache License 2.0 | 5 votes |
private int layout(GridView.Tree t, int x, int y, int w, int h, int index) { if (t == null) { return index; } if (t.splitType == Tree.NONE) { if (cellCount > index) { Component c = getComponent(index); c.setSize(w, h); c.setLocation(x, y); } return index + 1; } else if (t.splitType == Tree.V) { int h1 = (int) (t.splitPosition * h); int h2 = h - h1; setDivider(Tree.V, x, y + h1 - DIVIDER_SIZE / 2, w, DIVIDER_SIZE, h, t); index = layout(t.first, x, y, w, h1 - DIVIDER_SIZE / 2, index); return layout(t.second, x, y + h1 + DIVIDER_SIZE / 2, w, h2, index); } else if (t.splitType == Tree.H) { int w1 = (int) (t.splitPosition * w); int w2 = w - w1; setDivider(Tree.H, x + w1 - DIVIDER_SIZE / 2, y, DIVIDER_SIZE, h, w, t); index = layout(t.first, x, y, w1 - DIVIDER_SIZE / 2, h, index); return layout(t.second, x + w1 + DIVIDER_SIZE / 2, y, w2, h, index); } return index; }
Example 14
Source File: GuiUtil.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Centers the component on the screen */ public static void centerOnScreen(Component componentToMove) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); componentToMove.setLocation( (screenSize.width - componentToMove.getWidth()) / 2, (screenSize.height - componentToMove.getHeight()) / 2); }
Example 15
Source File: DialogLoggerUtil.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
/** * Center on screen ( abslute true/false (exact center or 25% upper left) )o * * @param c * @param absolute */ public static void centerOnScreen(final Component c, final boolean absolute) { final int width = c.getWidth(); final int height = c.getHeight(); final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); int x = (screenSize.width / 2) - (width / 2); int y = (screenSize.height / 2) - (height / 2); if (!absolute) { x /= 2; y /= 2; } c.setLocation(x, y); }
Example 16
Source File: AquaViewTabDisplayerUI.java From netbeans with Apache License 2.0 | 4 votes |
@Override protected void paintTabContent(Graphics g, int index, String text, int x, int y, int width, int height) { FontMetrics fm = getTxtFontMetrics(); // setting font already here to compute string width correctly g.setFont(getTxtFont()); int textW = width; if (isSelected(index)) { Component buttons = getControlButtons(); if( null != buttons ) { Dimension buttonsSize = buttons.getPreferredSize(); if( width < buttonsSize.width+ICON_X_PAD ) { buttons.setVisible( false ); } else { buttons.setVisible( true ); textW = width - (buttonsSize.width + ICON_X_PAD + 2*TXT_X_PAD); buttons.setLocation( x + textW+2*TXT_X_PAD-2, y + (height-buttonsSize.height)/2 ); } } } else { textW = width - 2 * TXT_X_PAD; } if (text.length() == 0) { return; } int textHeight = fm.getHeight(); int textY; int textX = x + TXT_X_PAD; if (index == 0) textX = x + 5; if (textHeight > height) { textY = (-1 * ((textHeight - height) / 2)) + fm.getAscent() - 1; } else { textY = (height / 2) - (textHeight / 2) + fm.getAscent(); } boolean slidedOut = false; WinsysInfoForTabbedContainer winsysInfo = displayer.getContainerWinsysInfo(); if( null != winsysInfo && winsysInfo.isSlidedOutContainer() ) slidedOut = false; if( isTabBusy( index ) && !slidedOut ) { Icon busyIcon = BusyTabsSupport.getDefault().getBusyIcon( isSelected( index ) ); textW -= busyIcon.getIconWidth() - 3 - TXT_X_PAD; busyIcon.paintIcon( displayer, g, textX, y+(height-busyIcon.getIconHeight())/2); textX += busyIcon.getIconWidth() + 3; } int realTextWidth = (int)HtmlRenderer.renderString(text, g, textX, textY, textW, height, getTxtFont(), UIManager.getColor("textText"), //NOI18N HtmlRenderer.STYLE_TRUNCATE, false); realTextWidth = Math.min(realTextWidth, textW); if( textW > realTextWidth ) textX += (textW - realTextWidth) / 2; HtmlRenderer.renderString(text, g, textX, textY, textW, height, getTxtFont(), UIManager.getColor("textText"), HtmlRenderer.STYLE_TRUNCATE, true); }
Example 17
Source File: DesignView.java From netbeans with Apache License 2.0 | 4 votes |
/** * Creates a new instance of GraphView. * @param service * @param implementationClass */ public DesignView(ProjectService service, FileObject implementationClass) { super(new BorderLayout()); this.service = service; this.implementationClass = implementationClass; scene = new ObjectScene() { @Override /** * Use our own traversal policy */ public Comparable<DesignerWidgetIdentityCode> getIdentityCode(Object object) { return new DesignerWidgetIdentityCode(scene,object); } }; zoomer = new ZoomManager(scene); scene.getActions().addAction(ActionFactory.createCycleObjectSceneFocusAction()); scene.setKeyEventProcessingType (EventProcessingType.FOCUSED_WIDGET_AND_ITS_PARENTS); mainLayer = new LayerWidget(scene); mainLayer.setPreferredLocation(new Point(0, 0)); mainLayer.setLayout(LayoutFactory.createVerticalFlowLayout( LayoutFactory.SerialAlignment.JUSTIFY, 12)); scene.addChild(mainLayer); mainWidget = new Widget(scene); mainWidget.setLayout(LayoutFactory.createVerticalFlowLayout( LayoutFactory.SerialAlignment.JUSTIFY, 12)); headerWidget = new LabelWidget(scene); headerWidget.setFont(scene.getFont().deriveFont(Font.BOLD)); headerWidget.setForeground(Color.GRAY); headerWidget.setBorder(BorderFactory.createEmptyBorder(6,28,0,0)); mainWidget.addChild(headerWidget); separatorWidget = new SeparatorWidget(scene, SeparatorWidget.Orientation.HORIZONTAL); separatorWidget.setForeground(Color.ORANGE); mainWidget.addChild(separatorWidget); contentWidget = new Widget(scene); contentWidget.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20)); contentWidget.setLayout(LayoutFactory.createVerticalFlowLayout( LayoutFactory.SerialAlignment.JUSTIFY, 16)); mainWidget.addChild(contentWidget); JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER){ /* (non-Javadoc) * @see java.awt.FlowLayout#layoutContainer(java.awt.Container) */ @Override public void layoutContainer( Container target ) { super.layoutContainer(target); Component[] components = target.getComponents(); double height = target.getSize().getHeight()/2; for (Component component : components) { Point location = component.getLocation(); component.setLocation( (int)location.getX(), (int)height ); } } }); panel.add(new JLabel(NbBundle.getMessage( DesignView.class, "LBL_Wait"))); add( panel,BorderLayout.CENTER); mainLayer.addChild(mainWidget); messageWidget = new Widget(scene); messageWidget.setLayout(LayoutFactory.createVerticalFlowLayout( LayoutFactory.SerialAlignment.JUSTIFY, 4)); mainLayer.addChild(messageWidget); scene.addObject(messageLayerKey, messageWidget); initServiceModel(); }
Example 18
Source File: CompMover.java From Math-Game with Apache License 2.0 | 4 votes |
/** * If a card is selected, it can be dragged */ @Override public void mousePressed(MouseEvent e) { selectedComponent = (Component) (e.getSource()); // System.out.println(selectedComponent.getParent()); // Point tempPoint = selectedComponent.getLocation(); offset = e.getPoint(); draggingCard = true; try { if (selectedComponent.getParent().equals(mathGame.getWorkspacePanel())) { mathGame.getWorkspacePanel().remove(selectedComponent); mathGame.getWorkspacePanel().revalidate(); mathGame.getMasterPane().add(selectedComponent, new Integer(1)); mathGame.getMasterPane().revalidate(); mathGame.getMasterPane().repaint(); // offset = selectedComponent.getLocationOnScreen(); // selectedComponent.setBounds(MouseInfo.getPointerInfo().getLocation().x, // MouseInfo.getPointerInfo().getLocation().y, // cardHomes[1].getSize().width, cardHomes[1].getSize().height); // selectedComponent.setLocation(MouseInfo.getPointerInfo().getLocation()); /* System.out.println(MouseInfo.getPointerInfo().getLocation()); System.out.println(selectedComponent.getLocation()); System.out.println(selectedComponent.getLocationOnScreen()); System.out.println(tempPoint); */ selectedComponent.setLocation(-200, -200); // selectedComponent.setSize(cardHomes[1].getSize().width, // cardHomes[1].getSize().height); } else if (selectedComponent.getParent().equals(mathGame.getHoldPanel())) { int tempX = selectedComponent.getX(); int tempY = selectedComponent.getLocationOnScreen().y; mathGame.getHoldPanel().remove(selectedComponent); mathGame.getHoldPanel().revalidate(); mathGame.getMasterPane().add(selectedComponent, new Integer(1)); mathGame.getMasterPane().revalidate(); mathGame.getMasterPane().repaint(); selectedComponent.setLocation(tempX, tempY); } /* else { System.out.println("normal workpanel:"+workPanel); System.out.println("parent:"+selectedComponent.getParent()); } */ } catch (Exception ex) { System.out.println("error removing from panel"); ex.printStackTrace(); } }
Example 19
Source File: VerticalFlowLayout.java From openchemlib-js with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Description of the Method * *@param target Description of Parameter */ public void layoutContainer(Container target) { synchronized (target.getTreeLock()) { Insets insets = target.getInsets(); int maxheight = target.getHeight() - (insets.top + insets.bottom) - 2 * _vgap; int maxwidth = target.getWidth() - (insets.left + insets.right) - 2 * _hgap; int nmembers = target.getComponentCount(); Dimension preferredSize = preferredLayoutSize(target); Dimension targetSize = target.getSize(); int y = (_valign == TOP) ? insets.top : (_valign == CENTER) ? (targetSize.height - preferredSize.height) / 2 : targetSize.height - preferredSize.height - insets.bottom; for (int i = 0; i < nmembers; i++) { Component m = target.getComponent(i); if (m.isVisible()) { Dimension d = m.getPreferredSize(); if (_hfill ) { m.setSize(maxwidth, d.height); d.width = maxwidth; } else { m.setSize(d.width, d.height); } if ((y + d.height) <= maxheight) { if (y > 0) { y += _vgap; } int x = (_halign == LEFT) ? insets.left : (_halign == CENTER) ? (targetSize.width - d.width) / 2 : targetSize.width - d.width - insets.right; m.setLocation(x + _hgap, y + _vgap); y += d.getHeight(); } else { break; } } } } }
Example 20
Source File: Canvas.java From freecol with GNU General Public License v2.0 | 2 votes |
/** * Adds a component centered on this Canvas. * * @param comp The {@code Component} to add to this canvas. * @param i The layer to add the component to (see JLayeredPane). */ private void addCentered(Component comp, Integer i) { comp.setLocation((getWidth() - comp.getWidth()) / 2, (getHeight() - comp.getHeight()) / 2); this.add(comp, i); }