List of usage examples for javax.swing JFrame getHeight
public int getHeight()
From source file:io.github.jeremgamer.editor.panels.components.PanelsPanel.java
public PanelsPanel(JFrame frame, final PanelSave ps) { this.ps = ps; this.frame = frame; this.setSize(new Dimension(395, frame.getHeight() - 27 - 23)); this.setLocation(300, 0); this.setBorder(BorderFactory.createTitledBorder("Edition du panneau")); JPanel content = new JPanel(); JScrollPane scroll = new JScrollPane(content); scroll.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); scroll.setBorder(null);//from w w w .java 2 s. c o m content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS)); scroll.setPreferredSize(new Dimension(382, frame.getHeight() - 27 - 46 - 20)); JPanel namePanel = new JPanel(); name.setPreferredSize(new Dimension(this.getWidth() - 280, 30)); name.setEditable(false); namePanel.add(new JLabel("Nom :")); namePanel.add(name); namePanel.add(Box.createRigidArea(new Dimension(10, 1))); layout.addItem("Basique"); layout.addItem("Bordures"); layout.addItem("Ligne"); layout.addItem("Colonne"); layout.addItem("Grille"); layout.addItem("Empil"); layout.setPreferredSize(new Dimension(110, 30)); layout.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); cl.show(advanced, listContent[combo.getSelectedIndex()]); ps.set("layout", combo.getSelectedIndex()); ActionPanel.updateLists(); } }); namePanel.add(new JLabel("Disposition :")); namePanel.add(layout); namePanel.setPreferredSize(new Dimension(365, 50)); namePanel.setMaximumSize(new Dimension(365, 50)); content.add(namePanel); advanced.setPreferredSize(new Dimension(365, 300)); advanced.setMaximumSize(new Dimension(365, 300)); advanced.add(ble, listContent[0]); advanced.add(brdle, listContent[1]); advanced.add(lle, listContent[2]); advanced.add(rle, listContent[3]); advanced.add(gle, listContent[4]); advanced.add(cle, listContent[5]); content.add(advanced); topBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.top", combo.getSelectedItem()); } }); leftBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.left", combo.getSelectedItem()); } }); centerBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.center", combo.getSelectedItem()); } }); rightBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.right", combo.getSelectedItem()); } }); bottomBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); ps.set("border.bottom", combo.getSelectedItem()); } }); JPanel prefSize = new JPanel(); prefSize.setPreferredSize(new Dimension(365, 110)); prefSize.setMaximumSize(new Dimension(365, 110)); prefSize.setBorder(BorderFactory.createTitledBorder("Taille prfre")); JPanel prefSizePanel = new JPanel(); prefSizePanel.setLayout(new GridLayout(2, 4)); prefSizePanel.setPreferredSize(new Dimension(300, 55)); prefSizePanel.setMaximumSize(new Dimension(300, 55)); prefSizePanel.add(prefSizeEnabled); prefSizePanel.add(new JLabel("")); prefSizePanel.add(new JLabel("")); prefSizePanel.add(new JLabel("(en pixels)")); prefSizePanel.add(new JLabel("Largeur :")); prefSizePanel.add(prefWidth); prefSizePanel.add(new JLabel("Hauteur :")); prefSizePanel.add(prefHeight); prefWidth.setEnabled(false); prefHeight.setEnabled(false); prefSizeEnabled.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JCheckBox check = (JCheckBox) event.getSource(); ps.set("preferredSize", check.isSelected()); prefWidth.setEnabled(check.isSelected()); prefHeight.setEnabled(check.isSelected()); } }); prefWidth.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSpinner spinner = (JSpinner) event.getSource(); ps.set("preferredWidth", spinner.getValue()); } }); prefHeight.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSpinner spinner = (JSpinner) event.getSource(); ps.set("preferredHeight", spinner.getValue()); } }); prefSize.add(prefSizePanel); content.add(prefSize); JPanel insetsPanel = new JPanel(); insetsPanel.setBorder(BorderFactory.createTitledBorder("carts")); insetsPanel.setPreferredSize(new Dimension(365, 100)); insetsPanel.setMaximumSize(new Dimension(365, 100)); JPanel insetsContent = new JPanel(); insetsContent.setLayout(new BoxLayout(insetsContent, BoxLayout.PAGE_AXIS)); JPanel insetInput = new JPanel(); insetInput.setLayout(new GridLayout(2, 4)); insetInput.add(insetsEnabled); insetInput.add(new JLabel("")); insetInput.add(new JLabel("")); insetInput.add(new JLabel("(en pixels)")); insetInput.add(new JLabel("Horizontaux :")); insetInput.add(insetHz); insetInput.add(new JLabel("Verticaux :")); insetInput.add(insetVt); insetsEnabled.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JCheckBox check = (JCheckBox) event.getSource(); if (check.isSelected()) { insetHz.setEnabled(true); insetVt.setEnabled(true); ps.set("insets", true); } else { insetHz.setEnabled(true); insetVt.setEnabled(true); ps.set("insets", false); } } }); insetHz.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSpinner spinner = (JSpinner) event.getSource(); ps.set("insets.horizontal", spinner.getValue()); } }); insetVt.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { JSpinner spinner = (JSpinner) event.getSource(); ps.set("insets.vertical", spinner.getValue()); } }); insetsContent.add(insetInput); insetsPanel.add(insetsContent); content.add(insetsPanel); JPanel web = new JPanel(); web.setPreferredSize(new Dimension(365, 100)); web.setMaximumSize(new Dimension(365, 100)); web.setBorder(BorderFactory.createTitledBorder("Page Web")); JPanel webContent = new JPanel(); webContent.setLayout(new BorderLayout()); webContent.add(webEnabled, BorderLayout.NORTH); webEnabled.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JCheckBox check = (JCheckBox) e.getSource(); ps.set("web", check.isSelected()); if (check.isSelected() == true) { layout.setSelectedIndex(0); layout.setEnabled(false); ble.removeAllComponents(); ble.disableComponents(); adress.setEnabled(true); } else { ble.enableComponents(); layout.setEnabled(true); adress.setEnabled(false); } } }); JPanel webInput = new JPanel(); webInput.add(new JLabel("Adresse :")); adress.setPreferredSize(new Dimension(250, 30)); CaretListener caretUpdate = new CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent e) { JTextField text = (JTextField) e.getSource(); ps.set("web.adress", text.getText()); } }; adress.addCaretListener(caretUpdate); webInput.add(adress); webContent.add(webInput, BorderLayout.CENTER); web.add(webContent); JPanel background = new JPanel(); BorderLayout bLayout = new BorderLayout(); bLayout.setVgap(12); background.setLayout(bLayout); background.setBorder(BorderFactory.createTitledBorder("Couleur de fond")); background.setPreferredSize(new Dimension(365, 210)); background.setMaximumSize(new Dimension(365, 210)); cp.setPreferredSize(new Dimension(347, 145)); cp.setMaximumSize(new Dimension(347, 145)); opaque.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JCheckBox check = (JCheckBox) e.getSource(); ps.set("background.opaque", check.isSelected()); cp.enableComponents(check.isSelected()); } }); background.add(opaque, BorderLayout.NORTH); background.add(cp, BorderLayout.CENTER); JPanel image = new JPanel(); image.setBorder(BorderFactory.createTitledBorder("Image de fond")); image.setPreferredSize(new Dimension(365, 125)); image.setMaximumSize(new Dimension(365, 125)); image.setLayout(new BorderLayout()); try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.setEnabled(false); remove.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { File img = new File( "projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png"); if (img.exists()) { img.delete(); } browseImage.setEnabled(true); } }); JPanel top = new JPanel(); browseImage.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JButton button = (JButton) e.getSource(); String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "background.png"); nameBackground.setText(new File(path).getName()); ps.set("background.image", new File(path).getName()); button.setEnabled(false); size.setEnabled(true); size2.setEnabled(true); remove.setEnabled(true); } } }); bg.add(size); bg.add(size2); JPanel sizePanel = new JPanel(); sizePanel.setLayout(new BoxLayout(sizePanel, BoxLayout.PAGE_AXIS)); size.setEnabled(false); size2.setEnabled(false); sizePanel.add(size); sizePanel.add(size2); size.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { ps.set("background.size", 0); } }); size2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { ps.set("background.size", 1); } }); top.add(browseImage); top.add(sizePanel); remove.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { JButton button = (JButton) event.getSource(); new File("projects/" + Editor.getProjectName() + "/panels/" + name.getText() + "/background.png") .delete(); nameBackground.setText(""); ps.set("background.image", ""); button.setEnabled(false); } }); nameBackground.setFont(new Font("Sans Serif", Font.PLAIN, 15)); JPanel center = new JPanel(new BorderLayout()); center.add(nameBackground, BorderLayout.CENTER); center.add(remove, BorderLayout.EAST); image.add(top, BorderLayout.NORTH); image.add(center, BorderLayout.CENTER); content.add(web); content.add(background); content.add(image); this.add(scroll); }
From source file:gov.anl.cue.arcane.engine.matrix.MatrixModel.java
/** * Export an image./*from w ww .ja va 2 s.c o m*/ * * @param fileName the file name * @param variables the variables * @param knit the knit * @param split the split * @param fitness the fitness * @return true, if successful */ public boolean exportImage(String fileName, Set<String> variables, Set<String> knit, Set<String> split, String fitness) { // Attempt to create a new formulation class. try { // Create the graph. Graph<String, String> graph = this.exportImageBuildGraph(); // Draw the graph. JFrame frame = this.exportImageRenderGraph(graph); // Store the rendering frame. BufferedImage img = new BufferedImage(frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_INT_RGB); frame.getContentPane().paint(img.createGraphics()); ImageIO.write(img, fileName.substring(fileName.length() - 3), new File(fileName)); // Catch errors. } catch (Exception e) { // Note errors. return false; } // Return the default results. return true; }
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param frame to be positioned/*www . java 2s . co m*/ * * positions frame on screen relative to position of TOPFRAME. * Sets frame.alwaysOnTop to true if TOPFRAME is maximized. */ public static void positionFrameRelativeToTopFrame(final JFrame frame) { // not sure of safest surest way to get main window??? JFrame topFrame = (JFrame) UIRegistry.getTopWindow(); // for now this just sets the top of frame to the top of topFrame // if there is room on the left side of topFrame, frame is set so it's right edge is next to topFrame's left edge. // otherwise, if frame will fit, frame's left edge is aligned with topFrame's right edge. // If it won't fit then frame's right edge is aligned with right of edge of screen. if (topFrame != null) { int x = 0; int y = topFrame.getY(); Rectangle screenRect = topFrame.getGraphicsConfiguration().getBounds(); if (topFrame.getX() >= frame.getWidth()) { x = topFrame.getX() - frame.getWidth(); } else if (screenRect.width - topFrame.getX() - topFrame.getWidth() >= frame.getWidth()) { x = topFrame.getWidth(); } else { x = screenRect.width - frame.getWidth(); } frame.setBounds(x, y, frame.getWidth(), frame.getHeight()); frame.setAlwaysOnTop(topFrame.getExtendedState() == Frame.MAXIMIZED_BOTH || topFrame.getExtendedState() == Frame.MAXIMIZED_VERT || topFrame.getExtendedState() == Frame.MAXIMIZED_HORIZ); } }
From source file:au.org.ala.delta.intkey.Intkey.java
/** * Prompt the user to set the size of the main window *//* w ww. j a v a2 s . c om*/ @Action public void mnuItSetMainWindowSize() { JFrame mainFrame = getMainFrame(); int currentWidth = mainFrame.getWidth(); int currentHeight = mainFrame.getHeight(); SetMainWindowSizeDialog dlg = new SetMainWindowSizeDialog(mainFrame, currentWidth, currentHeight); show(dlg); try { Pair<Integer, Integer> newWidthHeight = dlg.getWidthAndHeight(); int newWidth = newWidthHeight.getFirst(); int newHeight = newWidthHeight.getSecond(); mainFrame.setSize(newWidth, newHeight); } catch (NumberFormatException ex) { displayErrorMessage(UIUtils.getResourceString("InvalidWidthOrHeight.error")); } }
From source file:net.sourceforge.pmd.util.designer.Designer.java
private void createRuleXML() { CreateXMLRulePanel rulePanel = new CreateXMLRulePanel(xpathQueryArea, codeEditorPane); JFrame xmlframe = new JFrame("Create XML Rule"); xmlframe.setContentPane(rulePanel);// w w w. j a v a 2 s . c o m xmlframe.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); xmlframe.setSize(new Dimension(600, 700)); xmlframe.addComponentListener(new java.awt.event.ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { JFrame tmp = (JFrame) e.getSource(); if (tmp.getWidth() < 600 || tmp.getHeight() < 700) { tmp.setSize(600, 700); } } }); int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height; int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width; xmlframe.pack(); xmlframe.setLocation((screenWidth - xmlframe.getWidth()) / 2, (screenHeight - xmlframe.getHeight()) / 2); xmlframe.setVisible(true); }
From source file:org.objectstyle.cayenne.modeler.pref.ComponentGeometry.java
/** * Binds this preference object to synchronize its state with a given component, * allowing to specify an initial offset compared to the stored position. *//*from w ww . ja v a 2 s .co m*/ public void bind(final JFrame frame, int initialWidth, int initialHeight, int maxOffset) { updateSize(frame, initialWidth, initialHeight); updateLocation(frame, maxOffset); frame.addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { setWidth(new Integer(frame.getWidth())); setHeight(new Integer(frame.getHeight())); } public void componentMoved(ComponentEvent e) { setX(new Integer(frame.getX())); setY(new Integer(frame.getY())); } }); }
From source file:org.openscience.jchempaint.application.JChemPaint.java
public static JChemPaintPanel showInstance(IChemModel chemModel, String title, boolean debug) { JFrame f = new JFrame(title + " - JChemPaint"); chemModel.setID(title);/* ww w . ja v a 2s. c o m*/ f.addWindowListener(new JChemPaintPanel.AppCloser()); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); JChemPaintPanel p = new JChemPaintPanel(chemModel, GUI_APPLICATION, debug, null); p.updateStatusBar(); f.setPreferredSize(new Dimension(800, 494)); //1.618 f.add(p); f.pack(); Point point = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint(); int w2 = (f.getWidth() / 2); int h2 = (f.getHeight() / 2); f.setLocation(point.x - w2, point.y - h2); f.setVisible(true); frameList.add(f); return p; }
From source file:org.squidy.nodes.ReacTIVision.java
public static void showErrorPopUp(String errorMessage) { //get screen size Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); //create pop up final JFrame frame = new JFrame(); frame.setResizable(false);//from w w w. j a va2 s . c o m frame.setAlwaysOnTop(true); frame.setUndecorated(true); JLabel text = new JLabel(" " + errorMessage + " "); frame.getContentPane().setBackground(Color.RED); text.setForeground(Color.WHITE); frame.add(text); frame.pack(); frame.setLocation((dim.width - frame.getWidth()) / 2, (dim.height - frame.getHeight()) / 2); frame.setVisible(true); frame.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent arg0) { frame.dispose(); } }); }
From source file:org.swiftexplorer.SwiftExplorer.java
private static void openMainWindow(final MainPanel cp) throws IOException { JFrame frame = new JFrame(Configuration.INSTANCE.getAppName()); Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); float ratio = (float) 0.8; Dimension windowSize = new Dimension((int) (screenSize.getWidth() * ratio), (int) (screenSize.getHeight() * ratio)); frame.setSize(windowSize.getSize()); frame.setLocationByPlatform(true);//from www . j a v a 2 s. c o m frame.setIconImage(ImageIO.read(SwiftExplorer.class.getResource("/icons/logo.png"))); frame.getContentPane().add(cp); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (cp.onClose()) { System.exit(0); } } }); cp.setOwner(frame); frame.setJMenuBar(cp.createMenuBar()); // center the frame int x = (int) ((screenSize.getWidth() - frame.getWidth()) / 2); int y = (int) ((screenSize.getHeight() - frame.getHeight()) / 2); frame.setLocation(x, y); frame.setVisible(true); }