java.awt.Dimension Java Examples
The following examples show how to use
java.awt.Dimension.
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: ImageViewer.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
/** * Opens a JDialog with the image viewer in it. * * @param image the image to show. * @param title the title of the dialog. * @param modal if <code>true</code>, the dialog is modal. */ public static void show( BufferedImage image, String title, boolean modal ) { JDialog f = new JDialog(); f.add(new ImageViewer(image), BorderLayout.CENTER); f.setTitle(title); f.setIconImage(ImageCache.getInstance().getBufferedImage(ImageCache.HORTONMACHINE_FRAME_ICON)); f.setModal(modal); f.pack(); int h = image.getHeight(); int w = image.getWidth(); if (h > w) { f.setSize(new Dimension(600, 800)); } else { f.setSize(new Dimension(800, 600)); } f.setLocationRelativeTo(null); // Center on screen f.setVisible(true); f.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); f.getRootPane().registerKeyboardAction(e -> { f.dispose(); }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); }
Example #2
Source File: FrameTool.java From FCMFrame with Apache License 2.0 | 6 votes |
/** * 屏幕居中方法 */ public static void setCenter(JFrame jframe) { Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int screenHeight = screenSize.height; int screenWidth = screenSize.width; jframe.setSize(screenWidth*2/3, screenHeight*2/3); int frameH = jframe.getHeight(); int frameW = jframe.getWidth(); jframe.setLocation((screenWidth - frameW) / 2, (screenHeight - frameH) / 2); try { String src = "images/logo.gif"; File f = new File(src); Image image = ImageIO.read(f); jframe.setIconImage(image); } catch (IOException e) { e.printStackTrace(); } }
Example #3
Source File: LuckMenuUI.java From littleluck with Apache License 2.0 | 6 votes |
/** * <p> * 重写方法,设置菜单的最小高度为20, 否则会出现菜单项大小不一致的情况。 * </p> * * <p> * Rewrite method, set the minimum height of the menu is 20, otherwise the * menu item size will be inconsistent situation. * </p> */ protected Dimension getPreferredMenuItemSize(JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap) { Dimension dimension = super.getPreferredMenuItemSize(c, checkIcon, arrowIcon, defaultTextIconGap); if (dimension != null && dimension.height < 20) { dimension.setSize(dimension.width, 20); } return dimension; }
Example #4
Source File: Test7163696.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public void run() { if (this.bar == null) { this.bar = new JScrollBar(JScrollBar.HORIZONTAL, 50, 10, 0, 100); this.bar.setPreferredSize(new Dimension(400, 20)); JFrame frame = new JFrame(); frame.add(this.bar); frame.pack(); frame.setVisible(true); } else if (40 != this.bar.getValue()) { System.out.println("name = " + UIManager.getLookAndFeel().getName()); System.out.println("value = " + this.bar.getValue()); } else { SwingUtilities.getWindowAncestor(this.bar).dispose(); this.bar = null; } }
Example #5
Source File: PushTransition2D.java From Pixelitor with GNU General Public License v3.0 | 6 votes |
@Override public Transition2DInstruction[] getInstructions(float progress, Dimension size) { AffineTransform transform1 = new AffineTransform(); AffineTransform transform2 = new AffineTransform(); if (type == LEFT) { transform2.translate(size.width * (1 - progress), 0); transform1.translate(size.width * (1 - progress) - size.width, 0); } else if (type == RIGHT) { transform2.translate(size.width * (progress - 1), 0); transform1.translate(size.width * (progress - 1) + size.width, 0); } else if (type == UP) { transform2.translate(0, size.height * (1 - progress)); transform1.translate(0, size.height * (1 - progress) - size.height); } else { transform2.translate(0, size.height * (progress - 1)); transform1.translate(0, size.height * (progress - 1) + size.height); } return new Transition2DInstruction[]{ new ImageInstruction(true, transform1, null), new ImageInstruction(false, transform2, null) }; }
Example #6
Source File: Utilities.java From javamelody with Apache License 2.0 | 6 votes |
/** * Fixe la taille exacte d'une JTable à celle nécessaire pour afficher les données. * @param table JTable */ public static void adjustTableHeight(final JTable table) { table.setPreferredScrollableViewportSize( new Dimension(-1, table.getPreferredSize().height)); // on utilise invokeLater pour configurer le scrollPane car lors de l'exécution ce cette méthode // la table n'est pas encore dans son scrollPane parent SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final JScrollPane scrollPane = MSwingUtilities.getAncestorOfClass(JScrollPane.class, table); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); // Puisqu'il n'y a pas d'ascenceur sur ce scrollPane, // il est inutile que la mollette de souris serve à bouger cet ascenseur, // mais il est très utile en revanche que ce scrollPane ne bloque pas l'utilisation // de la mollette de souris pour le scrollPane global de l'onglet principal. // On commence par enlever le listener au cas où la méthode soit appelée deux fois sur la même table. scrollPane.removeMouseWheelListener(DELEGATE_TO_PARENT_MOUSE_WHEEL_LISTENER); scrollPane.addMouseWheelListener(DELEGATE_TO_PARENT_MOUSE_WHEEL_LISTENER); } }); }
Example #7
Source File: ErrorPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void btnStackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStackActionPerformed StringWriter sw = new StringWriter(); exception.printStackTrace(new PrintWriter(sw)); JPanel pnl = new JPanel(); pnl.setLayout(new BorderLayout()); pnl.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); JTextArea ta = new JTextArea(); ta.setText(sw.toString()); ta.setEditable(false); JScrollPane pane = new JScrollPane(ta); pnl.add(pane); pnl.setMaximumSize(new Dimension(600, 300)); pnl.setPreferredSize(new Dimension(600, 300)); NotifyDescriptor.Message nd = new NotifyDescriptor.Message(pnl); DialogDisplayer.getDefault().notify(nd); }
Example #8
Source File: EditorPane.java From 3Dscript with BSD 2-Clause "Simplified" License | 6 votes |
/** * @return this EditorPane wrapped in a {@link RTextScrollPane}. */ public RTextScrollPane wrappedInScrollbars() { final RTextScrollPane sp = new RTextScrollPane(this); sp.setPreferredSize(new Dimension(600, 350)); sp.setIconRowHeaderEnabled(true); gutter = sp.getGutter(); // iconGroup = new IconGroup("bullets", "images/", null, "png", null); // gutter.setBookmarkIcon(iconGroup.getIcon("var")); // URL url = ClassLoader.getSystemClassLoader().getResource("eye.png"); // ImageIcon icon = new ImageIcon(url); // gutter.setBookmarkIcon(icon); // gutter.setBookmarkingEnabled(true); return sp; }
Example #9
Source File: WPrinterJob.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private void init(Component parent, String title, String message, String buttonText) { Panel p = new Panel(); add("Center", new Label(message)); Button btn = new Button(buttonText); btn.addActionListener(this); p.add(btn); add("South", p); pack(); Dimension dDim = getSize(); if (parent != null) { Rectangle fRect = parent.getBounds(); setLocation(fRect.x + ((fRect.width - dDim.width) / 2), fRect.y + ((fRect.height - dDim.height) / 2)); } }
Example #10
Source File: LogFileViewer.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Inits the. * * @param file the file * @param d the d */ public void init(File file, Dimension d) { createMenus(); this.logFile = file; this.textArea = new JTextArea(); // Copy Action copyAction = this.textArea.getActionMap().get(DefaultEditorKit.copyAction); copyAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK)); copyAction.setEnabled(true); this.scrollPane = new JScrollPane(this.textArea); this.setContentPane(this.scrollPane); this.scrollPane.setPreferredSize(d); boolean doneLoadingFile = loadFile(); if (!doneLoadingFile) { this.dispose(); return; } this.pack(); this.setVisible(true); }
Example #11
Source File: JMapViewer.java From Course_Generator with GNU General Public License v3.0 | 6 votes |
public JMapViewer(TileCache tileCache, int downloadThreadCount) { super(); JobDispatcher.setMaxWorkers(downloadThreadCount); tileSource = new OsmTileSource.Mapnik(); tileController = new TileController(tileSource, tileCache, this); mapMarkerList = new LinkedList<>(); mapPolygonList = new LinkedList<>(); mapRectangleList = new LinkedList<>(); mapMarkersVisible = true; mapRectanglesVisible = true; mapPolygonsVisible = true; tileGridVisible = false; setLayout(null); initializeZoomSlider(); setMinimumSize(new Dimension(tileSource.getTileSize(), tileSource.getTileSize())); setPreferredSize(new Dimension(400, 400)); setDisplayPosition(new Coordinate(50, 9), 3); // setToolTipText(""); }
Example #12
Source File: FrameDemo.java From littleluck with Apache License 2.0 | 5 votes |
private static JComponent createFrameSpaceholder(JFrame frame) { JPanel framePlaceholder = new JPanel(); Dimension prefSize = frame.getPreferredSize(); prefSize.width += 12; prefSize.height += 12; framePlaceholder.setPreferredSize(prefSize); return framePlaceholder; }
Example #13
Source File: GUILabelingTool.java From Pixie with MIT License | 5 votes |
/** * Pack the window and set a new min size in order to avoid the resize to a * value where the components do no longer fit. */ private void packGUI() { // avoid a min size greater than the new arrangement of panel size this.setMinimumSize(new Dimension(0, 0)); this.pack(); // make the screen the minimum size when the components still fit this.setMinimumSize(this.getSize()); }
Example #14
Source File: StringTableCellEditor.java From netbeans with Apache License 2.0 | 5 votes |
public StringTableCellEditor(final JTextField textField) { super(textField); customEditorButton.addActionListener(this); // ui-tweaking customEditorButton.setFocusable(false); customEditorButton.setFocusPainted(false); customEditorButton.setMargin(new Insets(0, 0, 0, 0)); customEditorButton.setPreferredSize(new Dimension(20, 10)); }
Example #15
Source File: MultiSeparatorUI.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Invokes the <code>getMaximumSize</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public Dimension getMaximumSize(JComponent a) { Dimension returnValue = ((ComponentUI) (uis.elementAt(0))).getMaximumSize(a); for (int i = 1; i < uis.size(); i++) { ((ComponentUI) (uis.elementAt(i))).getMaximumSize(a); } return returnValue; }
Example #16
Source File: MultiPopupMenuUI.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Invokes the <code>getMaximumSize</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public Dimension getMaximumSize(JComponent a) { Dimension returnValue = ((ComponentUI) (uis.elementAt(0))).getMaximumSize(a); for (int i = 1; i < uis.size(); i++) { ((ComponentUI) (uis.elementAt(i))).getMaximumSize(a); } return returnValue; }
Example #17
Source File: MultiScrollPaneUI.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Invokes the <code>getPreferredSize</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public Dimension getPreferredSize(JComponent a) { Dimension returnValue = ((ComponentUI) (uis.elementAt(0))).getPreferredSize(a); for (int i = 1; i < uis.size(); i++) { ((ComponentUI) (uis.elementAt(i))).getPreferredSize(a); } return returnValue; }
Example #18
Source File: ButtonUI.java From RipplePower with Apache License 2.0 | 5 votes |
protected void paintButtonPressed(Graphics g, AbstractButton b) { if (b.isContentAreaFilled()) { if (b instanceof RPButton) { RPButton link = (RPButton) b; if (link.getBtnGroup() != null && link.isLeftNode()) { float width = link.getWidth(); float height = link.getHeight(); int arc = link.getBtnGroup().getArc(); Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); RoundRectangle2D rect = new RoundRectangle2D.Float(0, 0, width, height, link.getBtnGroup().getArc(), arc); g2.setColor(getSelectColor()); g2.fill(rect); Rectangle2D rectFix = new Rectangle((int) width - arc, 0, (int) arc, (int) height); g2.fill(rectFix); g2.dispose(); } else { Dimension size = b.getSize(); g.setColor(getSelectColor()); g.fillRect(0, 0, size.width, size.height); } } } }
Example #19
Source File: BasicToolBarSeparatorUI.java From JDKSourceCode1.8 with MIT License | 5 votes |
public Dimension getPreferredSize( JComponent c ) { Dimension size = ( (JToolBar.Separator)c ).getSeparatorSize(); if ( size != null ) { return size.getSize(); } else { return null; } }
Example #20
Source File: PropertiesPanel.java From netbeans with Apache License 2.0 | 5 votes |
private void makeDialogWider(int delta) { Window w = SwingUtilities.getWindowAncestor(this); if (w != null) { Dimension size = w.getSize(); size.width += delta; w.setSize(size); } }
Example #21
Source File: JScrollBar.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * The scrollbar is flexible along it's scrolling axis and * rigid along the other axis. */ public Dimension getMinimumSize() { Dimension pref = getPreferredSize(); if (orientation == VERTICAL) { return new Dimension(pref.width, 5); } else { return new Dimension(5, pref.height); } }
Example #22
Source File: TimePicker.java From dsworkbench with Apache License 2.0 | 5 votes |
private void updateSize() { if (minutesExpanded) { setMinimumSize(new Dimension(260, 220)); setMaximumSize(getMinimumSize()); setPreferredSize(getMinimumSize()); } else { setMinimumSize(new Dimension(260, 160)); setMaximumSize(getMinimumSize()); setPreferredSize(getMinimumSize()); } if (pParent != null) { pParent.pack(); } }
Example #23
Source File: CompletionLayoutPopup.java From netbeans with Apache License 2.0 | 5 votes |
/** * Sets maximum size for appropriate JComponent, depending on wheteher * additional items are present */ private void setMaxSize(JComponent comp, Dimension maxSize) { if (comp instanceof JPanel) { comp.getComponent(0).setMaximumSize(maxSize); // JScrollPane } else { comp.setMaximumSize(maxSize); } }
Example #24
Source File: ImageHeaderBitmap.java From lams with GNU General Public License v2.0 | 5 votes |
public ImageHeaderBitmap(byte data[], int offset) { BufferedImage img = null; try { img = ImageIO.read(new ByteArrayInputStream(data, offset, data.length-offset)); } catch (IOException e) { LOG.log(POILogger.WARN, "Can't determine image dimensions", e); } // set dummy size, in case of dummy dimension can't be set size = (img == null) ? new Dimension(200,200) : new Dimension( (int)Units.pixelToPoints(img.getWidth()), (int)Units.pixelToPoints(img.getHeight()) ); }
Example #25
Source File: SquaresTransition2D.java From pumpernickel with MIT License | 5 votes |
protected float findMax(float t0, float t1) { if (t1 - t0 < .0001) return Math.max(t0, t1); Rectangle2D r = new Rectangle2D.Float(0, 0, 100, 100); float mid = t0 / 2f + t1 / 2f; Transition2DInstruction[] instrA = getInstructions(t0, new Dimension( 100, 100)); Transition2DInstruction[] instrB = getInstructions(mid, new Dimension( 100, 100)); Transition2DInstruction[] instrC = getInstructions(t1, new Dimension( 100, 100)); boolean validA = false; boolean validB = false; boolean validC = false; for (int a = 1; a < instrA.length; a++) { if (r.intersects((Rectangle2D) ((ImageInstruction) instrA[a]).clipping)) { validA = true; } if (r.intersects((Rectangle2D) ((ImageInstruction) instrB[a]).clipping)) { validB = true; } if (r.intersects((Rectangle2D) ((ImageInstruction) instrC[a]).clipping)) { validC = true; } } if (validA && validC) return Math.max(t0, t1); if (validA) { if (validB) { return findMax(mid, t1); } else { return findMax(t0, mid); } } else { throw new RuntimeException(); } }
Example #26
Source File: MetalScrollBarUI.java From hottub with GNU General Public License v2.0 | 5 votes |
public Dimension getPreferredSize( JComponent c ) { if ( scrollbar.getOrientation() == JScrollBar.VERTICAL ) { return new Dimension( scrollBarWidth, scrollBarWidth * 3 + 10 ); } else // Horizontal { return new Dimension( scrollBarWidth * 3 + 10, scrollBarWidth ); } }
Example #27
Source File: LanderAvatar.java From GVGAI_GYM with Apache License 2.0 | 5 votes |
public LanderAvatar(Vector2d position, Dimension size, SpriteContent cnt) { //Init the sprite this.init(position, size); //Specific class default parameter values. loadDefaults(); //Parse the arguments. this.parseParameters(cnt); }
Example #28
Source File: MultiScrollBarUI.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Invokes the <code>getMinimumSize</code> method on each UI handled by this object. * * @return the value obtained from the first UI, which is * the UI obtained from the default <code>LookAndFeel</code> */ public Dimension getMinimumSize(JComponent a) { Dimension returnValue = ((ComponentUI) (uis.elementAt(0))).getMinimumSize(a); for (int i = 1; i < uis.size(); i++) { ((ComponentUI) (uis.elementAt(i))).getMinimumSize(a); } return returnValue; }
Example #29
Source File: JavaHelp.java From netbeans with Apache License 2.0 | 5 votes |
private void init(Runnable run) { this.run = run; JComponent c = ProgressHandleFactory.createProgressComponent(progressHandle); c.setPreferredSize(new Dimension(3 * c.getPreferredSize().width, 3 * c.getPreferredSize().height)); c.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); getContentPane().add(c); progressHandle.start(); getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(JavaHelp.class, "ACSD_Loading_Dialog")); //NOI18N pack(); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Dimension me = getSize(); setLocation((screen.width - me.width) / 2, (screen.height - me.height) / 2); }
Example #30
Source File: GraphicUtils.java From xyTalk-pc with GNU Affero General Public License v3.0 | 5 votes |
/** * Centers the window over a component (usually another window). The window * must already have been sized. * * @param window * Window to center. * @param over * Component to center over. */ public static void centerWindowOnComponent(Window window, Component over) { if ((over == null) || !over.isShowing()) { centerWindowOnScreen(window); return; } Point parentLocation = over.getLocationOnScreen(); Dimension parentSize = over.getSize(); Dimension size = window.getSize(); // Center it. int x = parentLocation.x + (parentSize.width - size.width) / 2; int y = parentLocation.y + (parentSize.height - size.height) / 2; // Now, make sure it's onscreen Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // This doesn't actually work on the Mac, where the screen // doesn't necessarily start at 0,0 if (x + size.width > screenSize.width) x = screenSize.width - size.width; if (x < 0) x = 0; if (y + size.height > screenSize.height) y = screenSize.height - size.height; if (y < 0) y = 0; window.setLocation(x, y); }