List of usage examples for java.awt Dimension Dimension
public Dimension(int width, int height)
From source file:Main.java
public static void setMaxWidth(JComponent comp, int width) { comp.setMaximumSize(new Dimension(width, Short.MAX_VALUE)); }
From source file:Main.java
/** * Ensures that all buttons are the same size, and that the chosen size is sufficient to contain the content of any. *//*from w w w.j a v a2 s .c o m*/ public static void tieButtonSizes(List<JButton> buttons) { int maxWidth = 0; int maxHeight = 0; for (JButton button : buttons) { Dimension buttonSize = button.getPreferredSize(); maxWidth = (int) Math.max(buttonSize.getWidth(), maxWidth); maxHeight = (int) Math.max(buttonSize.getHeight(), maxHeight); } Dimension maxButtonSize = new Dimension(maxWidth, maxHeight); for (JButton button : buttons) { // Seemingly, to get the GTK+ LAF to behave when there are buttons with and without icons, we need to set every size. button.setPreferredSize(maxButtonSize); button.setMinimumSize(maxButtonSize); button.setMaximumSize(maxButtonSize); button.setSize(maxButtonSize); } }
From source file:Main.java
/** * Returns current screen size of the display. In case of multi-display system it returns the * screen size for default one.//from w w w .j ava 2s . c o m * @return */ public static Dimension getEffectiveScreenSize() { GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); int width = gd.getDisplayMode().getWidth(); int height = gd.getDisplayMode().getHeight(); return new Dimension(width, height); }
From source file:Main.java
public static void center(Window window, double ratio) { Rectangle bounds = window.getGraphicsConfiguration().getBounds(); int width = bounds.width / 2; int height = bounds.height / 2; int centerX = (int) (bounds.x + bounds.width * ratio); int centerY = (int) (bounds.y + bounds.height * ratio); window.setLocation(centerX - width / 2, centerY - height / 2); window.setPreferredSize(new Dimension(width, height)); window.pack();//w w w . j a v a 2 s . c o m }
From source file:Main.java
/** * Returns the size of the given text computed towards to the given * component./*w ww . j av a 2s .c om*/ * * @param c the component where the text is contained * @param text the text to measure * @return the dimensions of the text */ public static Dimension getStringSize(Component c, String text) { // get metrics from the graphics FontMetrics metrics = c.getFontMetrics(c.getFont()); // get the height of a line of text in this font and render context int hgt = metrics.getHeight(); // get the advance of my text in this font and render context int adv = metrics.stringWidth(text); // calculate the size of a box to hold the text with some padding. return new Dimension(adv + 2, hgt + 2); }
From source file:Main.java
public static boolean canVScroll(JViewport viewport) { JScrollPane scrollPane = (JScrollPane) viewport.getParent(); Rectangle availR = scrollPane.getBounds(); Component view = viewport.getView(); Dimension viewPrefSize = view != null ? view.getPreferredSize() : new Dimension(0, 0); Dimension extentSize = viewport.toViewCoordinates(availR.getSize()); boolean canVScroll = true; if (view instanceof Scrollable) canVScroll = !((Scrollable) view).getScrollableTracksViewportHeight(); if (canVScroll && (viewPrefSize.height <= extentSize.height)) canVScroll = false;//from w w w . j a v a 2s. c o m return canVScroll; }
From source file:Main.java
public static void centerWindow(Window window, int width, int height) { // Get screen size final Toolkit tk = Toolkit.getDefaultToolkit(); final Dimension screensize = tk.getScreenSize(); // Set window minimum size window.setMinimumSize(new Dimension((int) Math.floor(screensize.getWidth() * 0.3), (int) Math.floor(screensize.getHeight() * 0.3))); // Set window size if (width == 0f) width = (int) Math.floor(screensize.getWidth() * 0.8); if (height == 0f) height = (int) Math.floor(screensize.getHeight() * 0.8); window.setPreferredSize(new Dimension(width, height)); int left = (int) (screensize.getWidth() - width) / 2; int right = (int) (screensize.getHeight() - height) / 2; ;//w w w. ja v a2 s . com // Center window window.setLocation(left, right); }
From source file:Main.java
public static Dimension getSize(Component c, int sizeflag) { if (c == null) { return new Dimension(0, 0); }/*from w w w .ja v a2 s . c o m*/ //special case due to swing bug: html labels need to know the current parent layout's size if (c instanceof JLabel) { View v = (View) ((JLabel) c).getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey); if (v != null) { switch (sizeflag) { case MIN: { Dimension d = new Dimension(c.getPreferredSize()); d.width = 1; return d; } case PREF: { Dimension d = new Dimension(c.getPreferredSize()); return d; } case MAX: { Dimension d = new Dimension(10240, 10240); d.width = 1; return d; } } } } // switch (sizeflag) { case MIN: { return new Dimension(c.getMinimumSize()); } case PREF: { return new Dimension(c.getPreferredSize()); } case MAX: { return new Dimension(c.getMaximumSize()); } } return new Dimension(c.getPreferredSize()); }
From source file:Main.java
public static Dimension getPreferredSize(JComponent c, String text, Icon icon, int iconTextGap, int verticalAlignment, int horizontalAlignment, int verticalTextAlignment, int horizontalTextAlignment, Rectangle viewRect, Rectangle iconRect, Rectangle textRect) { viewRect.x = viewRect.y = 0;/*from w w w.j a va2s .c o m*/ viewRect.width = viewRect.height = Short.MAX_VALUE; layoutComponent(c, text, icon, iconTextGap, verticalAlignment, horizontalAlignment, verticalTextAlignment, horizontalTextAlignment, viewRect, iconRect, textRect); Rectangle size = iconRect.union(textRect); if (c.getInsets() != null) { addInsets(size, c.getInsets()); } return new Dimension(size.width, size.height); }
From source file:Main.java
private static Dimension getSliderDimension(int w, int h) { return new Dimension(w, h); }