Example usage for javax.swing JInternalFrame toFront

List of usage examples for javax.swing JInternalFrame toFront

Introduction

In this page you can find the example usage for javax.swing JInternalFrame toFront.

Prototype

public void toFront() 

Source Link

Document

Brings this internal frame to the front.

Usage

From source file:ScrollDesktop.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JDesktopPane desk = new ScrollDesktop();
    desk.setPreferredSize(new Dimension(1000, 1000));
    getContentPane().add(new JScrollPane(desk), "Center");
    JInternalFrame f1 = new JInternalFrame("Frame 1");
    f1.getContentPane().add(new JLabel("This is frame f1"));
    f1.setResizable(true);/*from   ww  w .  ja v a  2s  . co  m*/
    f1.pack();
    f1.setVisible(true);
    desk.add(f1, new Integer(10));

    JInternalFrame f2 = new JInternalFrame("Frame 2");
    f2.getContentPane().add(new JLabel("Content for f2"));
    f2.setResizable(true);
    f2.pack();
    f2.setVisible(true);
    desk.add(f2, new Integer(20));

    JInternalFrame f3 = new JInternalFrame("Frame 3");
    f3.getContentPane().add(new JLabel("Content for f3"));
    f3.setResizable(true);
    f3.pack();
    f3.setVisible(true);
    desk.add(f3, new Integer(20));

    f3.toFront();
    try {
        f3.setSelected(true);
    } catch (java.beans.PropertyVetoException ignored) {
    }

    pack();
    setSize(300, 300);
    setVisible(true);
}

From source file:com.opendoorlogistics.studio.AppFrame.java

@Override
public void addInternalFrame(JInternalFrame frame, FramePlacement placement) {
    desktopPane.add(frame);/*  ww  w.j a  v a  2s. com*/
    frame.pack();
    frame.setVisible(true);

    // if(ScriptEditor.class.isInstance(frame)){
    // try {
    // frame.setMaximum(true);
    // } catch (PropertyVetoException e) {
    // }
    // }
    // else{

    // WindowState state = PreferencesManager.getSingleton().getWindowState(frame)
    if (placement == FramePlacement.AUTOMATIC) {
        boolean placed = false;
        if (ODLInternalFrame.class.isInstance(frame)) {
            ODLInternalFrame odlFrame = (ODLInternalFrame) frame;
            placed = odlFrame.placeInLastPosition(desktopScrollPane.getViewport().getBounds());
        }

        if (!placed) {
            LayoutUtils.placeInternalFrame(desktopPane, frame);
        }
    } else if (placement == FramePlacement.CENTRAL) {
        Dimension desktopSize = desktopPane.getSize();
        Dimension frameSize = frame.getSize();
        int x = (desktopSize.width - frameSize.width) / 2;
        int y = (desktopSize.height - frameSize.height) / 2;
        frame.setLocation(x, y);
    } else if (placement == FramePlacement.CENTRAL_RANDOMISED) {
        Dimension desktopSize = desktopPane.getSize();
        Dimension frameSize = frame.getSize();
        Dimension remaining = new Dimension(Math.max(0, desktopSize.width - frameSize.width),
                Math.max(0, desktopSize.height - frameSize.height));
        Dimension halfRemaining = new Dimension(remaining.width / 2, remaining.height / 2);
        Random random = new Random();
        int x = remaining.width / 4 + random.nextInt(halfRemaining.width);
        int y = remaining.height / 4 + random.nextInt(halfRemaining.height);
        frame.setLocation(x, y);
    }
    frame.toFront();
}