List of usage examples for java.awt Component getWidth
public int getWidth()
From source file:com.moneydance.modules.features.importlist.table.HeaderRenderer.java
@Override public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) { Component component = this.defaultHeaderTableCellRenderer.getTableCellRendererComponent(table, value, hasFocus, hasFocus, row, column); if (component instanceof JComponent) { JComponent jComponent = (JComponent) component; jComponent.setBorder(new EmptyBorder(1, 1, 1, 1)); jComponent.setOpaque(false);/*from w w w. ja v a 2s . c o m*/ if (jComponent instanceof JLabel) { JLabel jLabel = (JLabel) jComponent; jLabel.setHorizontalAlignment(SwingConstants.LEFT); } } component.setFont(Preferences.getHeaderFont()); component.setForeground(Preferences.getHeaderForeground()); component.setSize( new Dimension(component.getWidth(), Helper.INSTANCE.getPreferences().getHeaderRowHeight())); component.setMinimumSize( new Dimension(component.getWidth(), Helper.INSTANCE.getPreferences().getHeaderRowHeight())); component.setPreferredSize( new Dimension(component.getWidth(), Helper.INSTANCE.getPreferences().getHeaderRowHeight())); component.setMaximumSize( new Dimension(component.getWidth(), Helper.INSTANCE.getPreferences().getHeaderRowHeight())); return component; }
From source file:org.kchine.rpf.PoolUtils.java
public static void locateInScreenCenter(Component c) { Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize(); c.setLocation((screenDim.width - c.getWidth()) / 2, (screenDim.height - c.getHeight()) / 2); }
From source file:edworld.pdfreader4humans.PDFReader.java
private void draw(Component component, Graphics2D graphics, Color inkColor, Color backgroundColor, boolean showStructure, Map<String, Font> fonts) { for (Component child : component.getChildren()) draw(child, graphics, inkColor, backgroundColor, showStructure, fonts); if (component instanceof BoxComponent && showStructure) { graphics.setColor(boxColor(backgroundColor)); graphics.drawRect((int) component.getFromX(), (int) component.getFromY(), (int) component.getWidth(), (int) component.getHeight()); graphics.setColor(inkColor);/*www .j a v a2 s . c om*/ } else if (component instanceof GroupComponent && showStructure) { graphics.setColor(groupColor(backgroundColor)); graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getWidth()), Math.round(component.getHeight())); graphics.setColor(inkColor); } else if (component instanceof MarginComponent && showStructure) { graphics.setColor(marginColor(backgroundColor)); graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getWidth()), Math.round(component.getHeight())); graphics.setColor(inkColor); } else if (component.getType().equals("line")) graphics.drawLine(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getToX()), Math.round(component.getToY())); else if (component.getType().equals("rect")) graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getWidth()), Math.round(component.getHeight())); else if (component instanceof TextComponent) { graphics.setFont(font((TextComponent) component, fonts)); graphics.drawString(((TextComponent) component).getText(), component.getFromX(), component.getToY()); } }
From source file:org.eclipse.jubula.rc.swing.driver.RobotAwtImpl.java
/** * Implementation of the mouse move. The mouse is moved into the graphics component. * @param graphicsComponent The component to move to * @param constraints The more specific constraints. Use this, for example * when you want the click point to be relative to a part * of the component (e.g. tree node, table cell, etc) * rather than the overall component itself. May be * <code>null</code>. * @param xPos xPos in component * @param yPos yPos in component// w w w .ja v a 2 s. c o m * @param xAbsolute true if x-position should be absolute * @param yAbsolute true if y-position should be absolute * @param clickOptions The click options * @throws StepExecutionException If the click delay is interrupted or the * event confirmation receives a timeout. */ private void moveImpl(Object graphicsComponent, final Rectangle constraints, final int xPos, final boolean xAbsolute, final int yPos, final boolean yAbsolute, ClickOptions clickOptions) throws StepExecutionException { if (clickOptions.isScrollToVisible()) { ensureComponentVisible((Component) graphicsComponent, constraints); m_eventFlusher.flush(); } Component component = (Component) graphicsComponent; Rectangle bounds = null; bounds = new Rectangle(getLocation(component, new Point(0, 0))); bounds.width = component.getWidth(); bounds.height = component.getHeight(); if (constraints != null) { bounds.x += constraints.x; bounds.y += constraints.y; bounds.height = constraints.height; bounds.width = constraints.width; } Point p = PointUtil.calculateAwtPointToGo(xPos, xAbsolute, yPos, yAbsolute, bounds); // Move if necessary if (isMouseMoveRequired(p)) { if (log.isDebugEnabled()) { log.debug("Moving mouse to: " + p); //$NON-NLS-1$ } IRobotEventConfirmer confirmer = null; if (clickOptions.isConfirmClick()) { InterceptorOptions options = new InterceptorOptions( new long[] { AWTEvent.MOUSE_MOTION_EVENT_MASK }); confirmer = m_interceptor.intercept(options); } Point startpoint = m_mouseMotionTracker.getLastMousePointOnScreen(); if (startpoint == null) { // If there is no starting point the center of the root component is used Component root = SwingUtilities.getRoot(component); Component c = (root != null) ? root : component; startpoint = getLocation(c, null); } Point[] mouseMove = MouseMovementStrategy.getMovementPath(startpoint, p, clickOptions.getStepMovement(), clickOptions.getFirstHorizontal()); for (int i = 0; i < mouseMove.length; i++) { m_robot.mouseMove(mouseMove[i].x, mouseMove[i].y); m_eventFlusher.flush(); } if (confirmer != null) { confirmer.waitToConfirm(component, new MouseMovedAwtEventMatcher()); } } }
From source file:UserInterface.GarbageCollectorRole.GarbageCollectorWorkAreaJPanel.java
public static BufferedImage getScreenShot(Component component) { BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB); component.paint(image.getGraphics()); return image; }
From source file:org.wandora.application.gui.topicpanels.webview.WebViewPanel.java
private void handleComponentEvent(ComponentEvent e) { try {/* ww w .j a va 2 s . c o m*/ Component c = this; if (this.getParent() != null) c = this.getParent(); final int w = c.getWidth(); final int h = c.getHeight() - 35; Dimension d = new Dimension(w, h); if (this.getParent() != null) { this.setPreferredSize(d); this.setMinimumSize(d); this.setMaximumSize(d); } if (webView != null && w > 1 && h > 1) { Platform.runLater(new Runnable() { @Override public void run() { webView.setMinSize(w, h); webView.setMaxSize(w, h); webView.setPrefSize(w, h); } }); } revalidate(); repaint(); } catch (Exception ex) { } }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Sets the location of the specified child relative to the location * of the specified parent and then makes it visible. * This method is mainly useful for windows, frames and dialogs. * //from w w w .j a v a 2 s . co m * @param parent The visible parent. * @param child The child to display. */ public static void setLocationRelativeTo(Component parent, Component child) { if (parent == null || child == null) return; int x = parent.getX() + parent.getWidth(); int y = parent.getY(); int childWidth = child.getWidth(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); if (x + childWidth > screenSize.getWidth()) { if (childWidth < parent.getX()) x = parent.getX() - childWidth; else x = (int) (screenSize.getWidth() - childWidth); } child.setLocation(x, y); child.setVisible(true); }
From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java
/** * Creates default columns for the table from * the data model using the <code>getColumnCount</code> method * defined in the <code>TableModel</code> interface. * * Clears any existing columns before creating the * new columns based on information from the model. * * Overrides base class behaviour by setting the column width as a % of the * viewport width./* w w w .j ava 2 s . co m*/ */ public void createDefaultColumnsFromModel() { TableModel m = getModel(); if (m != null) { // Remove any current columns TableColumnModel cm = getColumnModel(); while (cm.getColumnCount() > 0) { cm.removeColumn(cm.getColumn(0)); } // get parent width int parentWidth = 0; Component parent = getParent(); if (parent != null) { parentWidth = parent.getWidth(); } // Create new columns from the data model info int columnCount = m.getColumnCount(); for (int i = 0; i < m.getColumnCount(); i++) { int width = tableModel.getColumnWidth(i); if (width == 0) { width = parentWidth / columnCount; } else { //Width is a % of the viewport width width = (width * parentWidth) / 100; } TableColumn newColumn = new TableColumn(i); newColumn.setPreferredWidth(width); addColumn(newColumn); } } }
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Sets the location of the specified child relative to the passed * bounds./* ww w . jav a2 s . c o m*/ * This method is mainly useful for windows, frames and dialogs. * * @param parentBounds The bounds of the parent. * @param child The child to display. */ public static void setLocationRelativeTo(Rectangle parentBounds, Component child) { if (child == null) return; if (parentBounds == null) parentBounds = new Rectangle(0, 0, 5, 5); int x = parentBounds.x + parentBounds.width; int y = parentBounds.y; int childWidth = child.getWidth(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); if (x + childWidth > screenSize.getWidth()) { if (childWidth < parentBounds.x) x = parentBounds.x - childWidth; else x = (int) (screenSize.getWidth() - childWidth); } child.setLocation(x, y); child.setVisible(true); }
From source file:FirstStatMain.java
private static BufferedImage getScreenShot(Component com) { BufferedImage image = new BufferedImage(com.getWidth(), com.getHeight(), BufferedImage.TYPE_INT_RGB); com.paint(image.getGraphics());//w w w .j av a 2 s . co m return image; }