Example usage for javax.swing JFrame setBounds

List of usage examples for javax.swing JFrame setBounds

Introduction

In this page you can find the example usage for javax.swing JFrame setBounds.

Prototype

public void setBounds(int x, int y, int width, int height) 

Source Link

Document

The width or height values are automatically enlarged if either is less than the minimum size as specified by previous call to setMinimumSize .

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    JFrame Main = new JFrame("Gradient Mask");
    JLabel imageLayer = new JLabel();
    JLabel maskLayer = new JLabel();
    BufferedImage image = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    BufferedImage gradientMask = new GradientImage(image.getWidth(), image.getHeight(),
            new Color[] { new Color(255, 255, 255, 125), Color.BLACK }, GradientImage.RADIAL_FROM_CENTER)
                    .getImage();//  ww w .j  av  a2s.c  o  m
    Main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Main.setBounds(100, 50, image.getWidth(), image.getHeight());
    imageLayer.setBounds(0, 0, Main.getWidth(), Main.getHeight());
    maskLayer.setBounds(0, 0, Main.getWidth(), Main.getHeight());
    imageLayer.setIcon(new ImageIcon((Image) image));
    maskLayer.setIcon(new ImageIcon((Image) gradientMask));
    Main.getContentPane().add(imageLayer);
    imageLayer.add(maskLayer);
    Main.setVisible(true);
}

From source file:DualModal.java

public static void main(String args[]) {
    final JFrame frame1 = new JFrame("Left");
    final JFrame frame2 = new JFrame("Right");
    frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button1 = new JButton("Left");
    JButton button2 = new JButton("Right");
    frame1.add(button1);//from   ww  w . j a va 2  s . c om
    frame2.add(button2);
    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JButton source = (JButton) e.getSource();

            JOptionPane pane = new JOptionPane("New label", JOptionPane.QUESTION_MESSAGE);
            pane.setWantsInput(true);
            JDialog dialog = pane.createDialog(frame2, "Enter Text");
            // dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL);
            dialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
            dialog.setVisible(true);
            String text = (String) pane.getInputValue();

            if (!JOptionPane.UNINITIALIZED_VALUE.equals(text) && text.trim().length() > 0) {
                source.setText(text);
            }
        }
    };
    button1.addActionListener(listener);
    button2.addActionListener(listener);
    frame1.setBounds(100, 100, 200, 200);
    frame1.setVisible(true);
    frame2.setBounds(400, 100, 200, 200);
    frame2.setVisible(true);
}

From source file:de.alpharogroup.duplicate.files.panels.progressbar.ImagePanelTest.java

/**
 * The main method.//from  ww w .  jav  a2s  .  co m
 *
 * @param args the arguments
 */
public static void main(String[] args) {
    final JFrame frame = new JFrame();
    frame.addWindowListener(new CloseWindow());
    frame.setTitle("ImagePanelTest");

    ApplicationContext ctx = SpringApplicationContext.getInstance().getApplicationContext();
    Resource resource = ctx.getResource("classpath:images/EngineHierarchy.PNG");

    Resource log4jconfig = ctx.getResource("classpath:conf/log4j/log4jconfig.xml");

    try {
        DOMConfigurator.configure(log4jconfig.getURL());
    } catch (FactoryConfigurationError e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    File imageFile = null;
    try {
        imageFile = resource.getFile();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    BufferedImage image = null;
    try {
        image = javax.imageio.ImageIO.read(imageFile);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    ImagePanel pnlIconPanel = new ImagePanel(image);
    frame.add(pnlIconPanel);
    frame.setBounds(0, 0, 534, 336);
    frame.setVisible(true);
}

From source file:EventDispatchThread.java

static void creatGUI() {
    JFrame window = new JFrame("Sketcher"); // Create the app window
    window.setBounds(30, 30, 300, 300); // Size
    window.setVisible(true);/*  w  w  w  .j  a  v  a 2 s .  c  o  m*/
}

From source file:Main.java

public static void setMaximized(JFrame frame) {
    Dimension screenSz = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setBounds(0, 0, screenSz.width, screenSz.height);
}

From source file:net.brtly.monkeyboard.MonkeyBoard.java

private static void createAndShowGui() {

    if (System.getProperty("os.name").toLowerCase().startsWith("mac")) {

        LOG.debug("MAC OS detected (" + System.getProperty("os.name")
                + "), applying extra UIManager configuration");
        //         UIManager.put("TabbedPaneUI",
        //               "javax.swing.plaf.metal.MetalTabbedPaneUI");
        //         UIManager.put("TabbedPane.selectedTabPadInsets", new Insets(2, 2,
        //               2, 1));
        //         UIManager.put("TabbedPane.tabsOpaque", Boolean.TRUE);
        //         UIManager.put("TabbedPane.darkShadow", new Color(122, 138, 153));
        //         // UIManager.put("TabbedPane.background", new Color(184,207,229));
        //         UIManager.put("TabbedPane.selectHighlight",
        //               new Color(255, 255, 255));
        //         // UIManager.put("TabbedPane.foreground", new Color(51,51,51));
        //         UIManager.put("TabbedPane.textIconGap", 4);
        //         UIManager.put("TabbedPane.highlight", new Color(255, 255, 255));
        //         UIManager.put("TabbedPane.unselectedBackground", new Color(238,
        //               238, 238));
        //         UIManager.put("TabbedPane.tabRunOverlay", 2);
        //         UIManager.put("TabbedPane.light", new Color(238, 238, 238));
        //         UIManager.put("TabbedPane.tabsOverlapBorder", Boolean.FALSE);
        //         UIManager.put("TabbedPane.selected", new Color(200, 221, 242));
        //         UIManager.put("TabbedPane.contentBorderInsets", new Insets(4, 2, 3,
        //               3));
        //         UIManager.put("TabbedPane.contentAreaColor", new Color(220, 221,
        //               242));
        //         UIManager.put("TabbedPane.tabAreaInsets", new Insets(2, 2, 0, 6));
        //         UIManager.put("TabbedPane.contentOpaque", Boolean.TRUE);
        //         UIManager.put("TabbedPane.focus", new Color(99, 130, 191));
        //         UIManager.put("TabbedPane.tabAreaBackground", new Color(218, 218,
        //               218));
        //         UIManager.put("TabbedPane.shadow", new Color(184, 207, 229));
        //         UIManager.put("TabbedPane.tabInsets", new Insets(0, 9, 1, 9));
        //         UIManager.put("TabbedPane.borderHightlightColor", new Color(99,
        //               130, 191));

        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Monkey Board");
    }/*  ww  w  .j ava  2 s  .  co m*/

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            JFrame frame = new JFrame("Monkey Board");
            frame.setBounds(120, 80, 600, 400);

            MasterControlPanel mcp = new MasterControlPanel(frame);
            frame.setVisible(true);
        }
    });
}

From source file:Main.java

/**
 * Centra un frame e ne setta le dimensioni
 *///from   ww  w.java2s  .  c o  m
public static void locateForm(JFrame f, int x, int y, int w, int h) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    x = (screenSize.width - w) / 2;
    y = (screenSize.height - h) / 2;
    f.setBounds(x, y, w, h);
}

From source file:Main.java

public static void centerFrame(JFrame frame, Preferences prefs, int defWidth, int defHeight) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int w = (int) ((screenSize.getWidth() / 100) * defWidth);
    int h = (int) ((screenSize.getHeight() / 100) * defHeight);
    int x = (int) ((screenSize.getWidth() - w) / 2);
    int y = (int) ((screenSize.getHeight() - h) / 2);
    if (prefs != null) {
        frame.setBounds(prefs.getInt("x", x), prefs.getInt("y", y), prefs.getInt("w", w), prefs.getInt("h", h));
    } else {/*from  w  ww.  jav  a2s. co m*/
        frame.setBounds(x, y, w, h);
    }
}

From source file:Main.java

/**
 * Centers the frame on the screen and sets its bounds. THis method should be
 * used after you call frame.pack() or frame.setSize().
 * @param frame// w  w  w  .jav  a 2  s. c  o m
 */
public static void centerFrame(JFrame frame) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Point center = ge.getCenterPoint();
    Rectangle bounds = ge.getMaximumWindowBounds();
    int w = Math.max(bounds.width / 2, Math.min(frame.getWidth(), bounds.width));
    int h = Math.max(bounds.height / 2, Math.min(frame.getHeight(), bounds.height));
    int x = center.x - w / 2, y = center.y - h / 2;

    frame.setBounds(x, y, w, h);

    if ((w == bounds.width) && (h == bounds.height)) {
        frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    }

    frame.validate();
}

From source file:Main.java

/**
 * <p><!-- Method description --></p>
 *
 *
 * @param frame//  w  w w .  j a  va 2 s. c  o  m
 */
public static void smartSetBounds(JFrame frame) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = 500;
    int height = 500;

    if (screenSize.height <= 600) {
        height = (int) (screenSize.height * .95);
    } else if (screenSize.height <= 1000) {
        height = (int) (screenSize.height * .90);
    } else if (screenSize.height <= 1200) {
        height = (int) (screenSize.height * .85);
    } else {
        height = (int) (screenSize.height * .80);
    }

    if (screenSize.width <= 1000) {
        width = (int) (screenSize.width * .95);
    } else if (screenSize.width <= 1200) {
        width = (int) (screenSize.width * .90);
    } else if (screenSize.width <= 1600) {
        width = (int) (screenSize.width * .85);
    } else {
        width = (int) (screenSize.width * .80);
    }

    frame.setBounds(0, 0, width, height);
}