Java Code Examples for javax.swing.JFrame#pack()

The following examples show how to use javax.swing.JFrame#pack() . 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: TaskManagerForm.java    From moa with GNU General Public License v3.0 6 votes vote down vote up
private static void createAndShowGUI() {

        // Create and set up the window.
        JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Create and set up the content pane.
        JPanel panel = new TaskManagerForm();
        panel.setOpaque(true); // content panes must be opaque
        frame.setContentPane(panel);

        // Display the window.
        frame.pack();
        //frame.setSize(400, 400);
        frame.setVisible(true);
    }
 
Example 2
Source File: ChartPanel.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
public static boolean showPointChart(String pLocalFile, Tribe pTribe) {
    try {
        List<String> file = new LinkedList<>();
        file.add(pLocalFile);
        ChartPanel p = new ChartPanel(file);
        JFrame f = new JFrame();
        f.setTitle("Spielerstatistik für " + pTribe.getName());
        f.add(p);
        f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        f.pack();
        f.setVisible(true);
    } catch (Exception e) {
        return false;
    }
    return true;
}
 
Example 3
Source File: Write3ByteBgrTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void showRes(final BufferedImage src,
                            final BufferedImage dst)
    {
    final int w = src.getWidth()+  dst.getWidth();
    final int h = Math.max(src.getHeight(), dst.getHeight());

    JFrame f = new JFrame("Test results");
    f.getContentPane().add( new JComponent() {
            public Dimension getPreferredSize() {
                return new Dimension(w,h);
            }

            public void paintComponent(Graphics g) {
                g.drawImage(src,0,0, null);
                g.drawImage(dst, src.getWidth(),0, null);
            }
        });
    f.pack();
    f.setVisible(true);
}
 
Example 4
Source File: TableExample2.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public TableExample2(String URL, String driver, String user,
        String passwd, String query) {
    JFrame frame = new JFrame("Table");
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    JDBCAdapter dt = new JDBCAdapter(URL, driver, user, passwd);
    dt.executeQuery(query);

    // Create the table
    JTable tableView = new JTable(dt);

    JScrollPane scrollpane = new JScrollPane(tableView);
    scrollpane.setPreferredSize(new Dimension(700, 300));

    frame.getContentPane().add(scrollpane);
    frame.pack();
    frame.setVisible(true);
}
 
Example 5
Source File: Test7163696.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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 6
Source File: OptionsConfigurationPanel.java    From moa with GNU General Public License v3.0 6 votes vote down vote up
private static void createAndShowGUI() {

        // Create and set up the window.
        JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Create and set up the content pane.
        Options options = new HoeffdingTree().getOptions();
        JPanel panel = new OptionsConfigurationPanel(null, options);
        // createLabelledOptionComponentListPanel(options
        // .getOptionArray(), null);
        panel.setOpaque(true); // content panes must be opaque
        frame.setContentPane(panel);

        // Display the window.
        frame.pack();
        // frame.setSize(400, 400);
        frame.setVisible(true);
    }
 
Example 7
Source File: DisplayAFP.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void showAlignmentImage(AFPChain afpChain, String result) {

		JFrame frame = new JFrame();

		String title = afpChain.getAlgorithmName() + " V."+afpChain.getVersion() + " : " + afpChain.getName1()  + " vs. " + afpChain.getName2() ;
		frame.setTitle(title);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

		AlignmentTextPanel txtPanel = new AlignmentTextPanel();
		txtPanel.setText(result);

		JMenuBar menu = MenuCreator.getAlignmentTextMenu(frame,txtPanel,afpChain,null);

		frame.setJMenuBar(menu);
		JScrollPane js = new JScrollPane();
		js.getViewport().add(txtPanel);
		js.getViewport().setBorder(null);
		//js.setViewportBorder(null);
		//js.setBorder(null);
		//js.setBackground(Color.white);

		frame.getContentPane().add(js);
		frame.pack();
		frame.setVisible(true);

	}
 
Example 8
Source File: Test8019180.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    if (this.test == null) {
        this.test = new JComboBox<>(ITEMS);
        this.test.addActionListener(this.test);
        JFrame frame = new JFrame();
        frame.add(test);
        frame.pack();
        frame.setVisible(true);
        SwingUtilities.invokeLater(this);
    } else {
        int index = this.test.getSelectedIndex();
        this.test.setSelectedIndex(1 + index);
        if (0 > this.test.getSelectedIndex()) {
            System.err.println("ERROR: no selection");
            System.exit(8019180);
        }
        SwingUtilities.getWindowAncestor(this.test).dispose();
        LATCH.countDown();
    }
}
 
Example 9
Source File: TransformedPaintTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void showFrame(final TransformedPaintTest t) {
    JFrame f = new JFrame("TransformedPaintTest");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final BufferedImage bi =
        new BufferedImage(R_WIDTH, R_HEIGHT, BufferedImage.TYPE_INT_RGB);
    JPanel p = new JPanel() {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g;
            t.render(g2d, R_WIDTH, R_HEIGHT);
            t.render(bi.createGraphics(), R_WIDTH, R_HEIGHT);
            g2d.drawImage(bi, R_WIDTH + 5, 0, null);

            g.setColor(Color.black);
            g.drawString("Rendered to Back Buffer", 10, 20);
            g.drawString("Rendered to BufferedImage", R_WIDTH + 15, 20);
        }
    };
    p.setPreferredSize(new Dimension(2 * R_WIDTH + 5, R_HEIGHT));
    f.add(p);
    f.pack();
    f.setVisible(true);
}
 
Example 10
Source File: ViewSetupExplorer.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public ViewSetupExplorer( final AS data, final String xml, final X io )
{
	frame = new JFrame( "ViewSetup Explorer" );
	panel = new ViewSetupExplorerPanel< AS, X >( this, data, xml, io );

	frame.add( panel, BorderLayout.CENTER );
	frame.setSize( panel.getPreferredSize() );

	frame.addWindowListener(
			new WindowAdapter()
			{
				@Override
				public void windowClosing( WindowEvent evt )
				{
					quit();
				}
			});

	frame.pack();
	frame.setVisible( true );

	// set the initial focus to the table
	panel.table.requestFocus();
}
 
Example 11
Source File: Display.java    From New-Beginner-Java-Game-Programming-Src with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
private void createDisplay(){
	frame = new JFrame(title);
	frame.setSize(width, height);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setResizable(false);
	frame.setLocationRelativeTo(null);
	frame.setVisible(true);
	
	canvas = new Canvas();
	canvas.setPreferredSize(new Dimension(width, height));
	canvas.setMaximumSize(new Dimension(width, height));
	canvas.setMinimumSize(new Dimension(width, height));
	canvas.setFocusable(false);
	
	frame.add(canvas);
	frame.pack();
}
 
Example 12
Source File: SummaryTab.java    From moa with GNU General Public License v3.0 5 votes vote down vote up
private static void createAndShowGUI() {

        // Create and set up the window.
        JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Create and set up the content pane.
        JPanel panel = new SummaryTab();
        panel.setOpaque(true); // content panes must be opaque
        frame.setContentPane(panel);

        // Display the window.
        frame.pack();
        frame.setVisible(true);
    }
 
Example 13
Source File: JTableAccessibleGetLocationOnScreen.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void constructInEDT() {
    String[] columnNames = { "col1", "col2", };
    Object[][] data = { { "row1, col1", "row1, col2" },
            { "row2, col1", "row2, col2" }, };

    frame = new JFrame(
            "JTable AccessibleTableHeader and AccessibleJTableCell test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    table = new JTable(data, columnNames);
    frame.add(table);
    frame.pack();
}
 
Example 14
Source File: TestDesktopIntegration.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("SpotBugs browser integration Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Add content to the window.
    frame.add(new TestDesktopIntegration());

    // Display the window.
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example 15
Source File: SettingsWindow.java    From tmc-intellij with MIT License 5 votes vote down vote up
public SettingsWindow() {
    logger.info("Building SettingsWindow. @SettingsWindow");
    frame = new JFrame();
    JPanel panel = new SettingsPanel(frame).getPanel();

    frame.add(panel);
    frame.setTitle("TMC Settings");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    frame.setResizable(true);
    frame.setSize(new Dimension(800, 500));
    frame.setAlwaysOnTop(true);
}
 
Example 16
Source File: TexturePaintPrintingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void printTexture() {
    f = new JFrame("Texture Printing Test");
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    final TexturePaintPrintingTest gpt = new TexturePaintPrintingTest();
    Container c = f.getContentPane();
    c.add(BorderLayout.CENTER, gpt);

    final JButton print = new JButton("Print");
    print.addActionListener(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            PrinterJob job = PrinterJob.getPrinterJob();
            job.setPrintable(gpt);
            final boolean doPrint = job.printDialog();
            if (doPrint) {
                try {
                    job.print();
                } catch (PrinterException ex) {
                    throw new RuntimeException(ex);
                }
            }
        }
    });
    c.add(print, BorderLayout.SOUTH);

    f.pack();
    f.setVisible(true);
}
 
Example 17
Source File: ConsoleFrame.java    From pumpernickel with MIT License 5 votes vote down vote up
private ConsoleFrame() {
	consoleWindow = new JFrame("Console");
	consoleWindow.getContentPane().add(scrollPane);
	scrollPane.setPreferredSize(new Dimension(900, 500));
	consoleWindow.pack();
	ContextualMenuHelper.add(console, "Save as...", new Runnable() {

		@Override
		public void run() {
			FileDialog fd = new FileDialog(consoleWindow, "Save TXT As...",
					FileDialog.SAVE);
			fd.pack();
			fd.setLocationRelativeTo(null);
			fd.setVisible(true);

			if (fd.getFile() == null)
				return;
			File file = new File(fd.getDirectory() + fd.getFile());
			try {
				if ((!file.exists()) && (!file.createNewFile()))
					throw new IOException("createNewFile failed for "
							+ file.getAbsolutePath());
				IOUtils.write(file, console.getText(), true);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	});
}
 
Example 18
Source File: Stats.java    From DeconvolutionLab2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Show the stats table in a frame if it is not yet embedded in another frame.
 */
public void show() {
	if (embedded)
		return;
	if (shown)
		return;
	if (mode == Mode.SHOW || mode == Mode.SHOWSAVE) {
		JFrame frame = new JFrame(name);
		frame.getContentPane().add(getPanel());
		frame.pack();
		Lab.setVisible(frame);
		shown = true;
	}
}
 
Example 19
Source File: FrontEnd.java    From microrts with GNU General Public License v3.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("microRTS Front End");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         
    frame.add(new FrontEnd(), BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
}
 
Example 20
Source File: PrintLatinCJKTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void showFrame() {
     JFrame f = new JFrame();
     JTextArea jta = new JTextArea(info, 4, 30);
     jta.setLineWrap(true);
     jta.setWrapStyleWord(true);
     f.add("Center", jta);
     JButton b = new JButton("Print");
     b.addActionListener(testInstance);
     f.add("South", b);
     f.pack();
     f.setVisible(true);
}