Java Code Examples for java.awt.Frame

The following examples show how to use java.awt.Frame. These examples are extracted from open source projects. 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 Project: megamek   Source File: MegaMekGUI.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void preferenceChange(PreferenceChangeEvent e) {
    // Update to reflect new skin
    if (e.getName().equals(GUIPreferences.SKIN_FILE)) {
        showMainMenu();
        frame.repaint();
    } else if (e.getName().equals(GUIPreferences.UI_THEME)) {
        try {
            UIManager.setLookAndFeel((String)e.getNewValue());
            // We went all Oprah and gave everybody frames...
            // so now we have to let everybody who got a frame
            // under their chair know that we updated our look
            // and feel.
            for (Frame f : Frame.getFrames()) {
                SwingUtilities.updateComponentTreeUI(f);
            }
            // ...and also all of our windows and dialogs, etc.
            for (Window w : Window.getWindows()) {
                SwingUtilities.updateComponentTreeUI(w);
            }
        } catch (Exception ex) {
            DefaultMmLogger.getInstance().error(getClass(), "preferenceChange(GUIPreferences.UI_THEME)", ex);
        }
    }
}
 
Example 2
public void start() {
    //Get things going.  Request focus, set size, et cetera
    setSize(200, 200);
    setVisible(true);
    validate();

    final Image image = new MultiResolutionCursor();

    int center = sizes[0] / 2;
    Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(
            image, new Point(center, center), "multi-resolution cursor");

    Frame frame = new Frame("Test Frame");
    frame.setSize(300, 300);
    frame.setLocation(300, 50);
    frame.add(new Label("Move cursor here"));
    frame.setCursor(cursor);
    frame.setVisible(true);
}
 
Example 3
@Override
public void init() {
    if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
        Sysout.createDialogWithInstructions(new String[]{
                "Press PASS, this test is for MacOS X only."});
        return;
    }

    System.setProperty("apple.awt.fileDialogForDirectories", "true");

    setLayout(new GridLayout(1, 1));

    fd = new FileDialog(new Frame(), "Open");

    showBtn = new Button("Show File Dialog");
    showBtn.addActionListener(this);
    add(showBtn);
    String[] instructions = {
            "1) Click on 'Show File Dialog' button. A file dialog will come up.",
            "2) Check that files can't be selected.",
            "3) Check that directories can be selected.",
            "4) Repeat steps 1 - 3 a few times for different files and directories.",
            "5) If it's true then the test passed, otherwise it failed."};
    Sysout.createDialogWithInstructions(instructions);
}
 
Example 4
Source Project: amidst   Source File: BiomeExporterDialog.java    License: GNU General Public License v3.0 6 votes vote down vote up
public BiomeExporterDialog(BiomeExporter biomeExporter, Frame parentFrame, BiomeProfileSelection biomeProfileSelection,
		Supplier<AmidstMenu> menuBarSupplier, Setting<String> lastBiomeExportPath) {
	// @formatter:off
	this.lastBiomeExportPath   = lastBiomeExportPath;
	this.biomeExporter         = biomeExporter;
	this.parentFrame           = parentFrame;
	this.menuBarSupplier       = menuBarSupplier;
	this.biomeProfileSelection = biomeProfileSelection;
	this.constraints           = new GridBagConstraints();
	this.labelPaneConstraints  = new GridBagConstraints();

	this.leftSpinner           = createCoordinateSpinner();
	this.topSpinner            = createCoordinateSpinner();
	this.rightSpinner          = createCoordinateSpinner();
	this.bottomSpinner         = createCoordinateSpinner();
	this.fullResCheckBox       = createFullResCheckbox();
	this.pathField             = createPathField();
	this.browseButton          = createBrowseButton();
	this.exportButton          = createExportButton();
	this.previewImage          = new BufferedImage(PREVIEW_SIZE, PREVIEW_SIZE, BufferedImage.TYPE_INT_ARGB);
	this.previewIcon           = new ImageIcon(new BufferedImage(PREVIEW_SIZE * 2, PREVIEW_SIZE * 2, BufferedImage.TYPE_INT_ARGB));
	this.previewLabel          = createPreviewLabel();
	this.dialog                = createDialog();
	// @formatter:on
}
 
Example 5
Source Project: jdk8u-jdk   Source File: ListRepaint.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) {
    for (int i = 0; i < 10; ++i) {
        final Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        ListRepaint list = new ListRepaint();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.select(0);
        frame.add(list);
        frame.setVisible(true);
        sleep();
        list.test();
        frame.dispose();
    }
}
 
Example 6
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        Frame frame = new Frame();
        frame.setSize(300, 200);

        TextField textField = new TextField();
        frame.add(textField);

        frame.setVisible(true);
        toolkit.realSync();

        textField.requestFocus();
        toolkit.realSync();

        // Check that the system assertion dialog does not block Java
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        toolkit.realSync();

        frame.setVisible(false);
        frame.dispose();
    }
 
Example 7
Source Project: Briss-2.0   Source File: BrissGUI.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void setStateAfterClusteringFinished(ClusterDefinition newClusters, PageExcludes newPageExcludes,
                                             File newSource) {
    updateWorkingSet(newClusters, newPageExcludes, newSource);

    previewPanel.removeAll();
    mergedPanels = new ArrayList<MergedPanel>();

    for (PageCluster cluster : workingSet.getClusterDefinition().getClusterList()) {
        MergedPanel p = new MergedPanel(cluster, this);
        previewPanel.add(p);
        mergedPanels.add(p);
    }
    progressBar.setString(Messages.getString("BrissGUI.clusteringRenderingFinished")); //$NON-NLS-1$

    setIdleState(); //$NON-NLS-1$
    pack();
    setExtendedState(Frame.MAXIMIZED_BOTH);
    previewPanel.repaint();
    showPreview.setVisible(true);
    startCropping.setVisible(true);
    progressBar.setVisible(false);
    repaint();
}
 
Example 8
Source Project: openjdk-jdk8u   Source File: WindowsLeak.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot r = new Robot();
    for (int i = 0; i < 100; i++) {
        Frame f = new Frame();
        f.pack();
        f.dispose();
    }
    r.waitForIdle();

    Disposer.addRecord(new Object(), () -> disposerPhantomComplete = true);

    while (!disposerPhantomComplete) {
        Util.generateOOME();
    }

    Vector<WeakReference<Window>> windowList =
                    (Vector<WeakReference<Window>>) AppContext.getAppContext().get(Window.class);

    if (windowList != null && !windowList.isEmpty()) {
        throw new RuntimeException("Test FAILED: Window list is not empty: " + windowList.size());
    }

    System.out.println("Test PASSED");
}
 
Example 9
Source Project: dragonwell8_jdk   Source File: ListRepaint.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) {
    for (int i = 0; i < 10; ++i) {
        final Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        ListRepaint list = new ListRepaint();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.select(0);
        frame.add(list);
        frame.setVisible(true);
        sleep();
        list.test();
        frame.dispose();
    }
}
 
Example 10
public static void main(final String[] args) {
    final Dimension expected = new Dimension(300, 300);
    final Frame frame = new Frame();
    final ScrollPane sp = new ScrollPane();
    sp.setSize(expected);
    frame.add(sp);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    sleep();
    final Dimension size = frame.getSize();
    if (size.width < expected.width || size.height < expected.height) {
        throw new RuntimeException(
                "Expected size: >= " + expected + ", actual size: " + size);
    }
    frame.dispose();
}
 
Example 11
Source Project: collect-earth   Source File: OpenTextFileListener.java    License: MIT License 6 votes vote down vote up
public OpenTextFileListener(Frame owner, String filePath, String title) {
	
	this.filePath = filePath;
	dialog = new JDialog(owner, title + " " + filePath); //$NON-NLS-1$
	dialog.setLocationRelativeTo(owner);
	dialog.setSize(new Dimension(300, 400));
	dialog.setModal(true);

	final BorderLayout layoutManager = new BorderLayout();

	final JPanel panel = new JPanel(layoutManager);

	dialog.add(panel);

	disclaimerTextArea = new JTextArea();
	disclaimerTextArea.setEditable(false);
	disclaimerTextArea.setLineWrap(true);
	disclaimerTextArea.setWrapStyleWord(true);
	final JScrollPane scrollPane = new JScrollPane(disclaimerTextArea);
	panel.add(scrollPane, BorderLayout.CENTER);
	scrollPane.setPreferredSize(new Dimension(250, 250));

	final JButton close = new JButton(Messages.getString("CollectEarthWindow.5")); //$NON-NLS-1$
	close.addActionListener( e -> dialog.setVisible(false) );
	panel.add(close, BorderLayout.SOUTH);
}
 
Example 12
Source Project: jdk8u60   Source File: TextAreaTwicePack.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) {
    final Frame frame = new Frame();
    final TextArea ta = new TextArea();
    frame.add(ta);
    frame.pack();
    frame.setVisible(true);
    sleep();
    final Dimension before = frame.getSize();
    frame.pack();
    final Dimension after = frame.getSize();
    if (!after.equals(before)) {
        throw new RuntimeException(
                "Expected size: " + before + ", actual size: " + after);
    }
    frame.dispose();
}
 
Example 13
boolean doTest() {
    Dimension beforeMaximizeCalled = new Dimension(300,300);

    frame = new Frame("Test Frame");
    frame.setUndecorated(true);
    frame.setFocusable(true);
    frame.setSize(beforeMaximizeCalled);
    frame.setVisible(true);
    frame.setExtendedState(Frame.MAXIMIZED_BOTH);
    frame.setExtendedState(Frame.NORMAL);

    Dimension afterMaximizedCalled= frame.getBounds().getSize();

    frame.dispose();

    if (beforeMaximizeCalled.equals(afterMaximizedCalled)) {
        return true;
    }
    return false;
}
 
Example 14
Source Project: jdk8u-jdk   Source File: D3DGraphicsDevice.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void addFSWindowListener(Window w) {
    // if the window is not a toplevel (has an owner) we have to use the
    // real toplevel to enter the full-screen mode with (4933099).
    if (!(w instanceof Frame) && !(w instanceof Dialog) &&
        (realFSWindow = getToplevelOwner(w)) != null)
    {
        ownerOrigBounds = realFSWindow.getBounds();
        WWindowPeer fp = (WWindowPeer)realFSWindow.getPeer();

        ownerWasVisible = realFSWindow.isVisible();
        Rectangle r = w.getBounds();
        // we use operations on peer instead of component because calling
        // them on component will take the tree lock
        fp.reshape(r.x, r.y, r.width, r.height);
        fp.setVisible(true);
    } else {
        realFSWindow = w;
    }

    fsWindowWasAlwaysOnTop = realFSWindow.isAlwaysOnTop();
    ((WWindowPeer)realFSWindow.getPeer()).setAlwaysOnTop(true);

    fsWindowListener = new D3DFSWindowAdapter();
    realFSWindow.addWindowListener(fsWindowListener);
}
 
Example 15
public static JTicketsBagSharedList newJDialog(JTicketsBagShared ticketsbagshared) {
    
    Window window = getWindow(ticketsbagshared);
    JTicketsBagSharedList mydialog;
    if (window instanceof Frame) { 
        mydialog = new JTicketsBagSharedList((Frame) window, true);
    } else {
        mydialog = new JTicketsBagSharedList((Dialog) window, true);
    } 
    
    mydialog.initComponents();
    
    mydialog.jScrollPane1.getVerticalScrollBar().setPreferredSize(new Dimension(35, 35));
    
    return mydialog;
}
 
Example 16
public WorldBrowserLine(Frame parent)
{
	// Try and find a single player world to default to
	File worldDir = null;
	for (int i=0; i<5; i++)
	{
		File dir = Minecraft.findWorldDir(i);
		if (Minecraft.isValidWorldDir(dir.toPath()))
		{
			worldDir = dir;
			break;
		}
	}
	
	line = new FileBrowserLine(parent, "World: ", "Open", worldDir, JFileChooser.DIRECTORIES_ONLY, null);		
	line.setFileListener( new FileChangedHandler() );

	onInternalFileChanged();
}
 
Example 17
private static void showModalDialog(Frame targetFrame) {

        Dialog dialog = new Dialog(targetFrame, true);

        dialog.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                passed = true;
                dialog.dispose();
            }
        });

        dialog.setSize(400, 300);
        dialog.setTitle("Modal Dialog!");

        clickOnModalDialog(dialog);
        dialog.setVisible(true);
    }
 
Example 18
Source Project: pdfxtk   Source File: StringRequester.java    License: Apache License 2.0 6 votes vote down vote up
public StringRequester(Frame parent, String title,
  String lines, String posText_, String negText) {
  
  super(parent, title, true);
  setLayout(new GridBagLayout());
  posText = posText_;
  
  add(new MultiLineLabel(lines), Awt.constraints(true));
  
  text = new TextField(30);
  add(text, Awt.constraints(true, 10, 4, GridBagConstraints.HORIZONTAL));
  
  Button pos = new Button(posText);
  add(pos, Awt.constraints(false, 10, 4, GridBagConstraints.HORIZONTAL));
  pos.addActionListener(this);
  
  Button neg = new Button(negText);
  add(neg, Awt.constraints(true, 10, 4, GridBagConstraints.HORIZONTAL));
  neg.addActionListener(this);
  
  pack();
}
 
Example 19
Source Project: hottub   Source File: XFramePeer.java    License: GNU General Public License v2.0 6 votes vote down vote up
void preInit(XCreateWindowParams params) {
    super.preInit(params);
    Frame target = (Frame)(this.target);
    // set the window attributes for this Frame
    winAttr.initialState = target.getExtendedState();
    state = 0;
    undecorated = Boolean.valueOf(target.isUndecorated());
    winAttr.nativeDecor = !target.isUndecorated();
    if (winAttr.nativeDecor) {
        winAttr.decorations = winAttr.AWT_DECOR_ALL;
    } else {
        winAttr.decorations = winAttr.AWT_DECOR_NONE;
    }
    winAttr.functions = MWMConstants.MWM_FUNC_ALL;
    winAttr.isResizable = true; // target.isResizable();
    winAttr.title = target.getTitle();
    winAttr.initialResizability = target.isResizable();
    if (log.isLoggable(PlatformLogger.Level.FINE)) {
        log.fine("Frame''s initial attributes: decor {0}, resizable {1}, undecorated {2}, initial state {3}",
                 Integer.valueOf(winAttr.decorations), Boolean.valueOf(winAttr.initialResizability),
                 Boolean.valueOf(!winAttr.nativeDecor), Integer.valueOf(winAttr.initialState));
    }
}
 
Example 20
private void executeTest() {

        GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        int x = 0;
        Frame f = null;
        for (x = 0; x < gd.length; x ++) {
            if (gd[x] != defDev) {
                secFrame = new Frame("Screen " + x + " - secondary", gd[x].getDefaultConfiguration());
                f = secFrame;
            } else {
                primaryFrame = new Frame("Screen " + x + " - primary", gd[x].getDefaultConfiguration());
                f = primaryFrame;
            }
            Button b = new Button("Print");
            b.addActionListener(this);
            f.add("South", b);
            f.addWindowListener (new WindowAdapter() {
                public void windowClosing(WindowEvent we) {
                    ((Window) we.getSource()).dispose();
                }
            });
            f.setSize(200, 200);
            f.setVisible(true);
        }
    }
 
Example 21
Source Project: TencentKona-8   Source File: bug7170657.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;

    Frame f = new Frame();

    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                         1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1,
                                             true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                   MouseEvent.NOBUTTON);

    test(f, mwe);
    test(f, mdme);
    test(f, me);

    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
 
Example 22
Source Project: binnavi   Source File: CFileChooser.java    License: Apache License 2.0 5 votes vote down vote up
private static int showNativeFileDialog(final JFileChooser chooser) {
  final FileDialog result = new FileDialog((Frame) chooser.getParent());

  result.setDirectory(chooser.getCurrentDirectory().getPath());

  final File selected = chooser.getSelectedFile();
  result.setFile(selected == null ? "" : selected.getPath());
  result.setFilenameFilter(new FilenameFilter() {
    @Override
    public boolean accept(final File dir, final String name) {
      return chooser.getFileFilter().accept(new File(dir.getPath() + File.pathSeparator + name));
    }
  });

  if (chooser.getDialogType() == SAVE_DIALOG) {
    result.setMode(FileDialog.SAVE);
  } else {
    // The native dialog only support Open and Save
    result.setMode(FileDialog.LOAD);
  }

  if (chooser.getFileSelectionMode() == DIRECTORIES_ONLY) {
    System.setProperty("apple.awt.fileDialogForDirectories", "true");
  }

  // Display dialog
  result.setVisible(true);

  System.setProperty("apple.awt.fileDialogForDirectories", "false");
  if (result.getFile() == null) {
    return CANCEL_OPTION;
  }

  final String selectedDir = result.getDirectory();
  chooser
      .setSelectedFile(new File(FileUtils.ensureTrailingSlash(selectedDir) + result.getFile()));
  return APPROVE_OPTION;
}
 
Example 23
Source Project: hottub   Source File: BidiEmbeddingTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    // to regress embedding test against old fix, call with an arg.  A window will pop
    // up causing awt lib to be loaded so the vm won't die with the unsatisfied link error.
    if (args.length > 0) {
        Frame f = new Frame();
        f.setSize(300, 300);
        f.setBackground(Color.white);
        f.show();
    }

    test1();
    test2();
}
 
Example 24
private static void renderText(Frame frame, Font f1) {
    VolatileImage vi = frame.createVolatileImage(256, 32);
    vi.validate(frame.getGraphicsConfiguration());

    Graphics2D g = vi.createGraphics();
    g.setFont(f1);
    g.drawString(text, 0, vi.getHeight()/2);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                       RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g.drawString(text, 0, vi.getHeight()/2);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                       RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    g.drawString(text, 0, vi.getHeight()/2);
    Toolkit.getDefaultToolkit().sync();
}
 
Example 25
Source Project: hottub   Source File: ScrollSelectionTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
public TestDialog( Frame frame, String name )
{
  super( frame, name );
  int scrollBoth = TextArea.SCROLLBARS_BOTH;
  instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
  add( "North", instructionsText );

  messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
  add("South", messageText);

  pack();

  show();
}
 
Example 26
Source Project: marathonv5   Source File: JavaElementPropertyAccessor.java    License: Apache License 2.0 5 votes vote down vote up
public String getOMapClassSimpleName() {
    if (component instanceof Frame || component instanceof Window || component instanceof Dialog
            || component instanceof JInternalFrame) {
        String className = component.getClass().getName();
        String simpleName = component.getClass().getSimpleName();
        Package pkg = component.getClass().getPackage();
        if (pkg == null) {
            return simpleName;
        }
        String pkgName = pkg.getName();
        if (!pkgName.startsWith("javax.swing") && !pkgName.startsWith("java.awt")) {
            return simpleName;
        }
        if (className.equals("javax.swing.ColorChooserDialog")) {
            return simpleName;
        }
        if (component instanceof JDialog) {
            Component[] components = ((JDialog) component).getContentPane().getComponents();
            if (components.length == 1 && components[0] instanceof JFileChooser) {
                return JFileChooser.class.getSimpleName() + "#Dialog";
            }
            if (components.length == 1 && components[0] instanceof JOptionPane) {
                return JOptionPane.class.getSimpleName() + "#Dialog";
            }
        }
        return null;
    }
    return null;
}
 
Example 27
Source Project: openjdk-jdk9   Source File: bug8024926.java    License: GNU General Public License v2.0 5 votes vote down vote up
public TestDialog(Frame frame, String name) {
    super(frame, name);
    int scrollBoth = TextArea.SCROLLBARS_BOTH;
    instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
    add("North", instructionsText);

    messageText = new TextArea("", 5, maxStringLength, scrollBoth);
    add("Center", messageText);

    pack();

    setVisible(true);
}
 
Example 28
Source Project: Robot-Overlord-App   Source File: FooterBar.java    License: GNU General Public License v2.0 5 votes vote down vote up
public FooterBar(Frame parent) {
	// create the status bar panel and shove it down the bottom of the frame
	
	this.setBorder(new BevelBorder(BevelBorder.LOWERED));
	//this.setPreferredSize(new Dimension(parent.getWidth(), 16));
	this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
	statusLabel = new JLabel("");
	statusLabel.setHorizontalAlignment(SwingConstants.LEFT);
	this.add(statusLabel);
}
 
Example 29
Source Project: openjdk-jdk9   Source File: FrameOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code Frame.getExtendedState()} through queue
 * @return the state of the frame
 */
public int getExtendedState() {
    return (runMapping(new MapAction<Integer>("getExtendedState") {
        @Override
        public Integer map() {
            return ((Frame) getSource()).getExtendedState();
        }
    }));
}
 
Example 30
Source Project: jdk8u-jdk   Source File: ServiceDialog.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructor for the "standard" print dialog (containing all relevant
 * tabs)
 */
public ServiceDialog(GraphicsConfiguration gc,
                     int x, int y,
                     PrintService[] services,
                     int defaultServiceIndex,
                     DocFlavor flavor,
                     PrintRequestAttributeSet attributes,
                     Frame frame)
{
    super(frame, getMsg("dialog.printtitle"), true, gc);
    initPrintDialog(x, y, services, defaultServiceIndex,
                    flavor, attributes);
}