Java Code Examples for javax.swing.JFrame.getContentPane()

The following are Jave code examples for showing how to use getContentPane() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: JavaCourse   File: Main.java   View Source Code Vote up 6 votes
/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 */
static void createAndShowGUI(JLabel worldLabel, JLabel statusLabel) {
	// Create and set up the window.
	JFrame frame = new JFrame("Blockworld");
	frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

	// add both labels in a vertical layout
	Container content = frame.getContentPane();
	content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));
	content.add(worldLabel);
	content.add(statusLabel);

	// Display the window.
	frame.pack();
	frame.setVisible(true);

}
 
Example 2
Project: jaer   File: JspikeStack.java   View Source Code Vote up 6 votes
/** Start a menu that allows the user to launch a number of demos for the 
 * JSpikeStack package.  To add a new demo to the menu:
 * 1) Add the appropriate element to the "Demos" enumerator (above);
 * 2) Add the button in demoMenu()
 * 3) Connect the enumerator element to the appropriate function in DemoLauncher through the switch statement.
 */
public static void demoMenu()
{
            
    JFrame frm=new JFrame();
    frm.setTitle("JSpikeStack demos");
    Container pane=frm.getContentPane();
    JButton button;
    
    pane.setLayout(new GridBagLayout());
    
    addDemoButton("Network Generation Demo","Read a network From XML and let it generate",Demos.GENERATE,pane);
    addDemoButton("Learning Demo","Read an AER file, initialize a random net, and run STDP learning",Demos.LEARN,pane);
    addDemoButton("Convolution Demo",  "Here we read data from the Silicon retina.  Two output layers respond to vertically and horizontally oriented features.",Demos.CONV,pane);
    addDemoButton("RC Network",  "Takes retina inputs and fires them to a smoothing network.",Demos.RCNET,pane);
    addDemoButton("Retina",  "In this demo we mimic the behaviour of a variety of types of retinal ganglion cell.",Demos.RETINA,pane);
    
    
    frm.setPreferredSize(new Dimension(500,500));
    frm.pack();
    frm.setVisible(true);
    frm.toFront();
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
}
 
Example 3
Project: jdk8u-jdk   File: TexturePaintPrintingTest.java   View Source Code Vote up 6 votes
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 4
Project: openjdk-jdk10   File: DefaultButtonModelCrashTest.java   View Source Code Vote up 6 votes
private void go() {

        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container contentPane = frame.getContentPane();
        ButtonModel model = new DefaultButtonModel();

        JCheckBox check = new JCheckBox("a bit broken");
        check.setModel(model);
        panel = new JPanel(new BorderLayout());
        panel.add(new JTextField("Press Tab (twice?)"), BorderLayout.NORTH);
        panel.add(check);
        contentPane.add(panel);
        frame.setLocationRelativeTo(null);
        frame.pack();
        frame.setVisible(true);
    }
 
Example 5
Project: jOthelloT   File: OthelloTournament.java   View Source Code Vote up 5 votes
public void saveGameRecord(JFrame frame, String competidores, PvpScore pvpScore) {
    try {
        frame.validate();
        frame.repaint();            
        Container c = frame.getContentPane();
        c.validate();
        c.repaint();
        BufferedImage im = new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
        c.paint(im.getGraphics());
        pvpScore.setGameRecord(im);
    } catch (Exception ex) {
        Logger.getLogger(OthelloTournament.class
                .getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 6
Project: OpenDA   File: PlotTest.java   View Source Code Vote up 5 votes
public static void testPlot_3() {
	System.out.println("==============================================================================");
	System.out.println("plotting in your own panel , ie embedding the plot");
	System.out.println("==============================================================================");

	// explicitly create a plot
	JFrame frame = new JFrame();
	frame.setSize(new Dimension(600,600)); ///TODO
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	Container pane = frame.getContentPane();
	//JPanel pane = new JPanel();
	Figure fig1 = new Figure(pane);
	
	// simple plot (opens new window or uses existing one)
	double xVals[] = {1.0,2.0,3.0,4.0,5.0};
	double yVals[] = {1.1,2.2,3.3,4.4,5.5};
	fig1.addPlot(xVals,yVals,"curve 1");
	fig1.drawnow();
	frame.setVisible(true);
	fig1.wait(1000);
	
	// elementary layout
	fig1.setXlabel("x-axis","x-unit");
	fig1.setYlabel("y-axis","y-unit");
	fig1.setAxisTitle("My title");
	fig1.drawnow();
	frame.setVisible(true);
	fig1.wait(1000);
	
	// add another curve
	double xVals2[] = {1.0,2.0,3.0,4.0,5.0};
	double yVals2[] = {4.1,4.2,4.3,4.4,4.5};
	fig1.addPlot(xVals2,yVals2,"curve 2");
	fig1.drawnow();
	frame.setVisible(true);
	fig1.wait(3000);
}
 
Example 7
Project: OpenDA   File: PlotTest.java   View Source Code Vote up 5 votes
public static void testPlot_5() {
	System.out.println("==============================================================================");
	System.out.println("plotting update - adding points");
	System.out.println("==============================================================================");

	// explicitly create a plot
	JFrame frame = new JFrame();
	frame.setSize(new Dimension(600,600)); ///TODO
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	Container pane = frame.getContentPane();
	Figure fig1 = new Figure(pane);
	frame.setVisible(true);
	// simple plot (opens new window or uses existing one)
	double xValsAll[] = {1.0,2.0,3.0,4.0,5.0,6.0,7.0};
	double yValsAll[] = {6.1,5.2,4.3,3.4,3.2,3.1,3.05};
	double xVals[];
	double yVals[];
	for(int i=1;i<=xValsAll.length;i++){
		xVals = new double[i];
		yVals = new double[i];
		for(int j=0;j<i;j++){ //copy relevant part
			xVals[j] = xValsAll[j];
			yVals[j] = yValsAll[j];
		}
		fig1.plot(xVals,yVals,"my curve");
		fig1.setXlabel("x-axis","x-unit");
		fig1.setYlabel("y-axis","y-unit");
		fig1.setAxisTitle("My title");
		fig1.drawnow();
		frame.setVisible(true);
	    //if(i==1){
	    //	frame.setVisible(true);
	    //}
		fig1.wait(1000);
	}
}
 
Example 8
Project: cuttlefish   File: TreeLayoutDemo.java   View Source Code Vote up 5 votes
/**
 * a driver for this demo
 */
public static void main(String[] args) {
    JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    content.add(new TreeLayoutDemo());
    frame.pack();
    frame.setVisible(true);
}
 
Example 9
Project: SpotSpotter   File: TextField.java   View Source Code Vote up 5 votes
public static void JTextFieldDemo1() {

		jf = new JFrame("TextField����");

		final Container contentPane = jf.getContentPane();
		contentPane.setLayout(new BorderLayout());

		jp = new JPanel();

		jtf1 = new JTextField();
		jtf2 = new JTextField(10);
		jtf3 = new JTextField("ָ���ı�����");
		jtf4 = new JTextField("ָ������+ָ������(ֻ��״̬)", 30);

		jtf3.setEnabled(false); // true���Ա༭
		jtf4.setFont(new Font("����", Font.BOLD | Font.ITALIC, 16)); // ���壬�Ƿ�Ӵ֡�б�壬�ֺ�
		// �����ı���ˮƽ���뷽ʽ
		jtf4.setHorizontalAlignment(SwingConstants.CENTER);

		jp.add(jtf1);
		jp.add(jtf2);
		jp.add(jtf3);
		jp.add(jtf4);

		contentPane.add(jp);

		jf.pack();
		jf.setLocation(400, 200);
		jf.setVisible(true);
		jf.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
	}
 
Example 10
Project: enigma-vk   File: ProgressDialog.java   View Source Code Vote up 5 votes
public ProgressDialog(JFrame parent) {
	
	// init frame
	m_frame = new JFrame(Constants.Name + " - Operation in progress");
	final Container pane = m_frame.getContentPane();
	FlowLayout layout = new FlowLayout();
	layout.setAlignment(FlowLayout.LEFT);
	pane.setLayout(layout);
	
	m_title = new JLabel();
	pane.add(m_title);
	
	// set up the progress bar
	JPanel panel = new JPanel();
	pane.add(panel);
	panel.setLayout(new BorderLayout());
	m_text = GuiTricks.unboldLabel(new JLabel());
	m_progress = new JProgressBar();
	m_text.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
	panel.add(m_text, BorderLayout.NORTH);
	panel.add(m_progress, BorderLayout.CENTER);
	panel.setPreferredSize(new Dimension(360, 50));
	
	// show the frame
	pane.doLayout();
	m_frame.setSize(400, 120);
	m_frame.setResizable(false);
	m_frame.setLocationRelativeTo(parent);
	m_frame.setVisible(true);
	m_frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
}
 
Example 11
Project: jdk8u-jdk   File: RadialGradientPrintingTest.java   View Source Code Vote up 5 votes
public static void createUI() {
    f = new JFrame("RadialGradient Printing Test");
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    final RadialGradientPrintingTest gpt = new RadialGradientPrintingTest();
    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 12
Project: jdk8u-jdk   File: LinearGradientPrintingTest.java   View Source Code Vote up 5 votes
public static void createUI() {
    f = new JFrame("LinearGradient Printing Test");
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    final LinearGradientPrintingTest gpt = new LinearGradientPrintingTest();
    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 13
Project: openjdk-jdk10   File: RadialGradientPrintingTest.java   View Source Code Vote up 5 votes
public static void createUI() {
    f = new JFrame("RadialGradient Printing Test");
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    final RadialGradientPrintingTest gpt = new RadialGradientPrintingTest();
    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 14
Project: openjdk-jdk10   File: TexturePaintPrintingTest.java   View Source Code Vote up 5 votes
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 15
Project: openjdk-jdk10   File: LinearGradientPrintingTest.java   View Source Code Vote up 5 votes
public static void createUI() {
    f = new JFrame("LinearGradient Printing Test");
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    final LinearGradientPrintingTest gpt = new LinearGradientPrintingTest();
    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 16
Project: cuttlefish   File: EdgeLabelDemo.java   View Source Code Vote up 5 votes
/**
 * a driver for this demo
 */
public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = frame.getContentPane();
    content.add(new EdgeLabelDemo());
    frame.pack();
    frame.setVisible(true);
}
 
Example 17
Project: cuttlefish   File: VertexImageShaperDemo.java   View Source Code Vote up 5 votes
/**
* a driver for this demo
*/
  public static void main(String[] args) {
      JFrame frame = new JFrame();
      Container content = frame.getContentPane();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      content.add(new VertexImageShaperDemo());
      frame.pack();
      frame.setVisible(true);
  }
 
Example 18
Project: visuflow-plugin   File: GraphManager.java   View Source Code Vote up 5 votes
/**
 * Creates an instance of JFrame {@link #panel} and adds the graph view {@link #view} to the {@link #panel}.
 * @author Shashank B S
 */
private void createPanel() {
	JFrame temp = new JFrame();
	temp.setLayout(new BorderLayout());
	panel = temp.getContentPane();
	panel.add(headerBar,BorderLayout.PAGE_START);
	panel.add(view);
	panel.add(settingsBar, BorderLayout.PAGE_END);
}
 
Example 19
Project: jreliability   File: ReliabilityViewer.java   View Source Code Vote up 4 votes
/**
 * Constructs and views {@link JFrame} with a given title and a list of {@link ReliabilityFunction}s.
 * 
 * @param title
 *            the title
 * @param reliabilityFunctions
 *            the reliabilityFunctions
 */
public static void view(String title, Map<String, ReliabilityFunction> reliabilityFunctions) {

	try {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	} catch (Exception e) {
		e.printStackTrace();
	}

	// Setup the aspects for the plot panel
	List<Aspect> aspects = new ArrayList<>();
	aspects.add(new ReliabilityFunctionAspect());
	aspects.add(new DistributionAspect());
	aspects.add(new DensityAspect());
	aspects.add(new FailureRateAspect());
	ReliabilityFunctionPlotPanel reliabilityFunctionPlotPanel = new ReliabilityFunctionPlotPanel(aspects);
	JPanel plotPanel = reliabilityFunctionPlotPanel.get(reliabilityFunctions);

	JPanel measuresPanel = new MeasuresPanel(reliabilityFunctions);

	JFrame frame = new JFrame();

	frame.setTitle(title);
	frame.setIconImage(getImageIcon().getImage());
	frame.setPreferredSize(new Dimension(1000, 500));
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	Container content = frame.getContentPane();
	frame.setLayout(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();
	c.ipady = 10;
	c.ipadx = 10;
	c.fill = GridBagConstraints.BOTH;

	c.gridx = 0;
	c.gridy = 5;
	c.weighty = 0.5;
	content.add(measuresPanel, c);
	c.gridx = 1;
	c.gridy = 5;
	c.weightx = 1.0;
	c.weighty = 0.5;
	content.add(plotPanel, c);

	c.gridx = 0;
	c.gridy = 20;
	c.gridwidth = 2;
	c.weighty = 0.0;
	c.fill = GridBagConstraints.HORIZONTAL;
	c.anchor = GridBagConstraints.PAGE_END;
	content.add(new JLabel(" \u00A9 JReliability.org 2008-2017"), c);

	frame.pack();
	frame.setVisible(true);
}
 
Example 20
Project: plain-text-archiver   File: UserInterface.java   View Source Code Vote up 4 votes
public static void loadInterface() {
	frame = new JFrame(WINDOW_TITLE);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	fileChooser = new JFileChooser();
	fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
	fileChooser.setFileFilter(new PtaFileFilter());

	Container contentPane = frame.getContentPane();
	SpringLayout layout = new SpringLayout();
	contentPane.setLayout(layout);
	contentPane.setPreferredSize(new Dimension(240, 200));

	JPanel panel = new JPanel();
	SpringLayout panelLayout = new SpringLayout();
	panel.setLayout(panelLayout);
	panel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
	layout.putConstraint(SpringLayout.NORTH, panel, 5, SpringLayout.NORTH, contentPane);
	layout.putConstraint(SpringLayout.EAST, panel, -10, SpringLayout.EAST, contentPane);
	layout.putConstraint(SpringLayout.SOUTH, panel, -30, SpringLayout.SOUTH, contentPane);
	layout.putConstraint(SpringLayout.WEST, panel, 10, SpringLayout.WEST, contentPane);
	contentPane.add(panel);

	titleLabel = new JLabel("Directory Details");
	titleLabel.setFont(new Font(titleLabel.getFont().getName(), Font.BOLD, 14));
	panelLayout.putConstraint(SpringLayout.HORIZONTAL_CENTER, titleLabel, 0, SpringLayout.HORIZONTAL_CENTER, panel);
	panelLayout.putConstraint(SpringLayout.NORTH, titleLabel, 5, SpringLayout.NORTH, panel);
	panel.add(titleLabel);

	JLabel filePathLabel = new JLabel("Path");
	filePathLabel.setFont(new Font(filePathLabel.getFont().getName(), Font.BOLD, 13));
	panelLayout.putConstraint(SpringLayout.NORTH, filePathLabel, 2, SpringLayout.SOUTH, titleLabel);
	panelLayout.putConstraint(SpringLayout.WEST, filePathLabel, 10, SpringLayout.WEST, panel);
	panel.add(filePathLabel);

	pathLabel = new JLabel();
	pathLabel.setFont(new Font(pathLabel.getFont().getName(), Font.PLAIN, 11));
	panelLayout.putConstraint(SpringLayout.NORTH, pathLabel, 0, SpringLayout.SOUTH, filePathLabel);
	panelLayout.putConstraint(SpringLayout.WEST, pathLabel, 10, SpringLayout.WEST, panel);
	panelLayout.putConstraint(SpringLayout.EAST, pathLabel, 10, SpringLayout.EAST, panel);
	panel.add(pathLabel);

	actionButton = new JButton();
	actionButton.setFocusable(false);
	layout.putConstraint(SpringLayout.NORTH, actionButton, 5, SpringLayout.SOUTH, panel);
	layout.putConstraint(SpringLayout.HORIZONTAL_CENTER, actionButton, 0, SpringLayout.HORIZONTAL_CENTER, contentPane);
	layout.putConstraint(SpringLayout.SOUTH, actionButton, -5, SpringLayout.SOUTH, contentPane);
	contentPane.add(actionButton);

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

	promptForFile();
}