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

The following examples show how to use javax.swing.JFrame#pack() . 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
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 2
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 3
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 4
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 5
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 6
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 7
@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 8
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 9
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 10
Source Project: dsworkbench   File: ChartPanel.java    License: 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 11
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 12
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);
}
 
Example 13
Source Project: microrts   File: FrontEnd.java    License: 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 14
/**
 * 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 15
Source Project: moa   File: SummaryTab.java    License: 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 16
Source Project: pumpernickel   File: ConsoleFrame.java    License: 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 17
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 18
Source Project: tmc-intellij   File: SettingsWindow.java    License: 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 19
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 20
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();
}