Example usage for javax.swing JFrame setContentPane

List of usage examples for javax.swing JFrame setContentPane

Introduction

In this page you can find the example usage for javax.swing JFrame setContentPane.

Prototype

@BeanProperty(bound = false, hidden = true, description = "The client area of the frame where child components are normally inserted.")
public void setContentPane(Container contentPane) 

Source Link

Document

Sets the contentPane property.

Usage

From source file:TableFilterDemo.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//*from www.  j a v a  2 s.  c  om*/
private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("TableFilterDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

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

From source file:levelBuilder.DialogMaker.java

/**
 * Displays key (i.e. legend) to the graph.
 *//*  w  w  w .jav  a  2  s .  c  o  m*/
private static void keyWindow() {
    JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0));

    BufferedImage img1 = null;
    BufferedImage img2 = null;
    BufferedImage img3 = null;
    BufferedImage img4 = null;
    BufferedImage img5 = null;
    try {
        img1 = ImageIO.read(new File(imgDir + "green.png"));
        img2 = ImageIO.read(new File(imgDir + "red.png"));
        img3 = ImageIO.read(new File(imgDir + "blue.png"));
        img4 = ImageIO.read(new File(imgDir + "circle.png"));
        img5 = ImageIO.read(new File(imgDir + "square.png"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    panel.add(new JLabel("Initial Node", new ImageIcon(img1), SwingConstants.LEFT));
    panel.add(new JLabel("End Node", new ImageIcon(img2), SwingConstants.LEFT));
    panel.add(new JLabel("Intermediate Node", new ImageIcon(img3), SwingConstants.LEFT));
    panel.add(new JLabel("Player Node", new ImageIcon(img4), SwingConstants.LEFT));
    panel.add(new JLabel("NPC Node", new ImageIcon(img5), SwingConstants.LEFT));

    JFrame frame = new JFrame("Key");
    panel.setOpaque(true);
    frame.setContentPane(panel);
    frame.pack();
    frame.setLocation(windowWidth, 0);
    frame.setVisible(true);

    verticalWindowPlacement += frame.getBounds().height + frame.getBounds().y;
    horizontalWindowPlacement += frame.getBounds().width;
}

From source file:TextInputDemo.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread.//  ww  w.  j  av  a 2 s  .co m
 */
private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

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

    //Create and set up the content pane.
    JComponent newContentPane = new TextInputDemo();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);

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

From source file:GenealogyExample.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//*ww w.j  av  a  2  s. co  m*/
private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("GenealogyExample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

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

From source file:JTop.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *///from ww w .  ja v a 2 s.c o  m
private static void createAndShowGUI(JPanel jtop) {
    // Create and set up the window.
    JFrame frame = new JFrame("JTop");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the content pane.
    JComponent contentPane = (JComponent) frame.getContentPane();
    contentPane.add(jtop, BorderLayout.CENTER);
    contentPane.setOpaque(true); // content panes must be opaque
    contentPane.setBorder(new EmptyBorder(12, 12, 12, 12));
    frame.setContentPane(contentPane);

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

From source file:components.DialogDemo.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread.//w ww.  j a  v a  2 s  .  c  o  m
 */
private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("DialogDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

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

From source file:levelBuilder.DialogMaker.java

/**
 * Provides other action buttons.//from   www.  j  a  v a 2 s .c o  m
 */
private static void actionWindow() {
    //Performs actions based on button pushes.
    class ActionHandler implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            switch (e.getActionCommand()) {
            case "edge":
                if (addedEdgeID != 0.0) {
                    DialogNode n = g.getSource(addedEdgeID);
                    int length;
                    if (n.getChildren().length == 0)
                        length = 0;
                    else
                        length = n.getChildren().length;
                    DialogNode[] newChildren = new DialogNode[length + 1];
                    for (int c = 0; c < newChildren.length - 1; c++)
                        newChildren[c] = n.getChildren()[c];
                    newChildren[newChildren.length - 1] = nodeMap.get(g.getDest(addedEdgeID).getText());
                    n.setChildren(newChildren);
                    addedEdgeID = 0.0;
                }
            case "save":
                saveGraph();
            case "check":
                //Checks for errors and displays them if they exist.
                ArrayList<String> errorList = new ArrayList<String>();
                errorList = dg.check();
                if (errorList.isEmpty()) {
                    JOptionPane.showMessageDialog(null, "No errors!", null, JOptionPane.PLAIN_MESSAGE);
                } else {
                    JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0));
                    for (String error : errorList)
                        panel.add(new JLabel(error));
                    JOptionPane.showMessageDialog(null, panel, "Errors. Fix these to continue.",
                            JOptionPane.PLAIN_MESSAGE);
                }
            case "reload":
                loadGraph(false);
            }
        }
    }

    JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0));

    //Buttons
    JButton button3 = new JButton("New edge");
    button3.setActionCommand("edge");
    button3.addActionListener(new ActionHandler());
    panel.add(button3);

    JButton button6 = new JButton("Save");
    button6.setActionCommand("save");
    button6.addActionListener(new ActionHandler());
    panel.add(button6);

    JButton button7 = new JButton("Check");
    button7.setActionCommand("check");
    button7.addActionListener(new ActionHandler());
    panel.add(button7);

    JButton button1 = new JButton("Reload");
    button1.setActionCommand("reload");
    button1.addActionListener(new ActionHandler());
    panel.add(button1);

    JFrame frame = new JFrame("Other Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(panel);
    frame.pack();
    frame.setLocation(windowWidth + horizontalWindowPlacement, 0);
    frame.setVisible(true);
}

From source file:DragPictureDemo2.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//*from  ww w  . ja v  a  2 s  .c o m*/
private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);

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

    //Create and set up the menu bar and content pane.
    DragPictureDemo2 demo = new DragPictureDemo2();
    frame.setJMenuBar(demo.createMenuBar());
    demo.setOpaque(true); //content panes must be opaque
    frame.setContentPane(demo);

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

From source file:levelBuilder.DialogMaker.java

/**
 * Displays properties of the currently selected node.
 * Also allows changing of most node properties. 
 *//*  w w w  .  j ava  2 s  .com*/
private static void nodePropertiesWindow() {
    //Performs actions based on button pushes.
    class ActionHandler implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            switch (e.getActionCommand()) {
            case "probSet":
                //parsing new probSet string to double[]
                ArrayList<double[]> probSets = selectedNode.getProbSets();
                if (probSetField.getText().equals(""))
                    probSets.remove(strategy);
                else {
                    String[] probSetInput = probSetField.getText().split(",");
                    int numChildren = probSetInput.length;
                    double[] newProbSet = new double[numChildren];
                    for (int c = 0; c < numChildren; c++)
                        newProbSet[c] = Double.parseDouble(probSetInput[c]);
                    if (probSets.size() > strategy)//TODO is this right?
                        probSets.add(strategy, newProbSet);
                    else
                        probSets.set(strategy, newProbSet);
                }
                selectedNode.setProbSets(probSets);
            case "npc":
                if (isNPCBoxChecked)
                    selectedNode.setNPC();
                else
                    selectedNode.setPC();
            case "text":
                dg.changeNodeText(selectedNode, textField.getText());
            case "strategy":
                strategy = Integer.parseInt(strategyField.getText());
            }
        }
    }

    JPanel fieldPanel = new JPanel(new GridLayout(0, 1, 0, 0));
    JPanel labelPanel = new JPanel(new GridLayout(0, 1, 0, 0));
    JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 0, 0));
    JPanel masterPanel = new JPanel(new GridLayout(0, 3, 0, 0));

    //Buttons, ckeckboxes, textboxes, and labels
    textField = new JTextField("May I buy your wand?", 10);
    fieldPanel.add(textField);
    labelPanel.add(new JLabel("Node Text"));
    JButton button1 = new JButton("Change");
    button1.setActionCommand("text");
    button1.addActionListener(new ActionHandler());
    buttonPanel.add(button1);

    npcBox = new JCheckBox();
    npcBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.DESELECTED)
                isNPCBoxChecked = false;
            else
                isNPCBoxChecked = true;
        }
    });
    fieldPanel.add(npcBox);
    labelPanel.add(new JLabel("NPC"));
    JButton button2 = new JButton("Change");
    button2.setActionCommand("npc");
    button2.addActionListener(new ActionHandler());
    buttonPanel.add(button2);

    childrenField = new JTextField("child1,child2", 10);
    fieldPanel.add(childrenField);
    labelPanel.add(new JLabel("Children"));
    JButton button3 = new JButton("");
    buttonPanel.add(button3);

    probSetField = new JTextField("0.1,0.9", 10);
    fieldPanel.add(probSetField);
    labelPanel.add(new JLabel("Probability set"));
    JButton button4 = new JButton("Change");
    button4.setActionCommand("probSet");
    button4.addActionListener(new ActionHandler());
    buttonPanel.add(button4);

    strategyField = new JTextField("0", 10);
    fieldPanel.add(strategyField);
    labelPanel.add(new JLabel("Strategy"));
    JButton button5 = new JButton("Change");
    button5.setActionCommand("strategy");
    button5.addActionListener(new ActionHandler());
    buttonPanel.add(button5);

    masterPanel.add(buttonPanel);
    masterPanel.add(fieldPanel);
    masterPanel.add(labelPanel);

    JFrame frame = new JFrame("Node Properties");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    fieldPanel.setOpaque(true);
    frame.setContentPane(masterPanel);
    frame.pack();
    frame.setLocation(windowWidth, verticalWindowPlacement);
    frame.setVisible(true);

    verticalWindowPlacement += frame.getBounds().height;
}

From source file:Converter.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//*from  ww  w.  j a va 2s .c  o  m*/
private static void createAndShowGUI() {
    // Set the look and feel.
    initLookAndFeel();

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

    // Create and set up the content pane.
    Converter converter = new Converter();
    converter.mainPane.setOpaque(true); // content panes must be opaque
    frame.setContentPane(converter.mainPane);

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