List of usage examples for java.awt Component setSize
public void setSize(Dimension d)
From source file:Main.java
public static final void defaultSize(Component component) { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Dimension size = new Dimension((int) (screen.getWidth() * 2 / 3), (int) (screen.getHeight() * 0.8)); component.setSize(size); }
From source file:Main.java
public static void resizeToScreenProportions(Component component, double xProportion, double yProportion) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension componentNewSize = new Dimension((int) (screenSize.width * yProportion), (int) (screenSize.height * xProportion)); component.setSize(componentNewSize); }
From source file:Main.java
private static void doSetSizeInEDT(final Component component, final int width, final int height) { component.setMaximumSize(new Dimension(width, height)); component.setMinimumSize(new Dimension(width, height)); component.setPreferredSize(new Dimension(width, height)); component.setSize(new Dimension(width, height)); }
From source file:Main.java
public static void setSizeToPreferredSizeTree(java.awt.Component c) { if (c instanceof java.awt.Container) { java.awt.Container container = (java.awt.Container) c; for (java.awt.Component component : container.getComponents()) { setSizeToPreferredSizeTree(component); }/*from w w w.j a v a 2 s. c om*/ } c.setSize(c.getPreferredSize()); }
From source file:Main.java
public static void setSize(final Component component, final int width, final int height) { if (component != null && width >= 0 && height >= 0) { runInEDT(() -> {//from ww w .j a va 2 s .c o m component.setMaximumSize(new Dimension(width, height)); component.setMinimumSize(new Dimension(width, height)); component.setPreferredSize(new Dimension(width, height)); component.setSize(new Dimension(width, height)); }); } }
From source file:Main.java
public static void constrainResize(ComponentEvent componentevent) { Component component = componentevent.getComponent(); Dimension dimension = component.getSize(); Dimension dimension1 = component.getMinimumSize(); Dimension dimension2 = new Dimension(dimension); boolean flag = false; if (dimension.width < dimension1.width) { flag = true;//from w w w . j a va 2 s. c o m dimension2.width = dimension1.width; } if (dimension.height < dimension1.height) { flag = true; dimension2.height = dimension1.height; } if (flag) component.setSize(dimension2); }
From source file:edu.ku.brc.af.core.NavBox.java
/** * Refreshes - meaning it makes sure it is resized (layed out) and drawn. * @param nbi the box to refresh// w w w . j ava2s . c om */ public static void refresh(final NavBoxItemIFace nbi) { if (nbi != null) { Component comp = nbi.getUIComponent(); comp.invalidate(); comp.doLayout(); comp.setSize(comp.getPreferredSize()); comp.repaint(); log.debug("comp " + comp.getPreferredSize() + " " + comp.getSize()); //$NON-NLS-1$ //$NON-NLS-2$ Container parentComp = nbi.getUIComponent().getParent(); if (parentComp instanceof NavBox) { refresh((NavBox) parentComp); } else if (parentComp instanceof JScrollPane) { // this must be a scrollable NavBox; // let's get the actual NavBox // container heirarchy is NavBox -> JScrollPane -> NavBoxItem parentComp = parentComp.getParent().getParent(); refresh((NavBox) parentComp); } } }
From source file:it.unibo.alchemist.boundary.gui.Perspective.java
private void setMainDisplay(final GraphicalOutputMonitor<T> gom) { if (!(gom instanceof Component)) { throw new IllegalArgumentException("Java Swing can not load a " + gom); }/*from w ww .j a v a2s .c o m*/ final Component gomComp = (Component) gom; if (main != null) { sim.removeOutputMonitor(main); gom.setStep(main.getStep()); gom.setRealTime(main.isRealTime()); final Component mainComp = (Component) main; gomComp.setSize(mainComp.getSize()); remove(mainComp); } else { gomComp.setSize(getSize()); } main = gom; add(gomComp, BorderLayout.CENTER); revalidate(); makeEffects(); if (sim != null) { new Thread(() -> sim.addOutputMonitor(main)).start(); } }
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.j av a 2 s . 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:pcgen.gui2.tools.Utility.java
/** * Centers a {@code Component} to the screen. * * @param dialog JDialog dialog to center *///from ww w.jav a 2 s. c om public static void centerComponent(Component dialog) { // since the Toolkit.getScreenSize() method is broken in the Linux implementation // of Java 5 (it returns double the screen size under xinerama), this method is // encapsulated to accomodate this with a hack. // TODO: remove the hack, once Java fixed this. // final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final Rectangle screenSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().getBounds(); final Dimension dialogSize = dialog.getSize(); if (dialogSize.height > screenSize.height) { dialogSize.height = screenSize.height; } if (dialogSize.width > screenSize.width) { dialogSize.width = screenSize.width; } dialog.setSize(dialogSize); dialog.setLocation(screenSize.x + ((screenSize.width - dialogSize.width) / 2), screenSize.y + ((screenSize.height - dialogSize.height) / 2)); }