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:Main.java

public static void main(String[] args) {
    String[] data = { "alist", "arithmetic", "ASCIInumbers", "A", "B", "list", "C", "D", "E", "numeral", "G",
            "F" };

    JCheckBox[] checkBox;//w  w w  .  j a  v a2  s .  com
    JButton submitButton;
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    JPanel contentPane = new JPanel();
    contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(5, 5));

    checkBox = new JCheckBox[data.length];
    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new GridLayout(0, 4, 5, 5));
    for (int i = 0; i < data.length; i++) {
        checkBox[i] = new JCheckBox(data[i]);
        centerPanel.add(checkBox[i]);
    }
    contentPane.add(centerPanel, BorderLayout.CENTER);

    JPanel footerPanel = new JPanel();
    submitButton = new JButton("Submit");
    footerPanel.add(submitButton);
    contentPane.add(footerPanel, BorderLayout.PAGE_END);

    frame.setContentPane(contentPane);
    frame.pack();
    frame.setLocationByPlatform(true);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    final ConfirmDialog dialog = new ConfirmDialog(f);
    final JTree tree = new JTree();
    tree.setVisibleRowCount(5);//from  ww  w . j a v  a 2s.  c  o m
    final JScrollPane treeScroll = new JScrollPane(tree);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton b = new JButton("Choose Tree Item");
    b.addActionListener(e -> {
        int result = dialog.showConfirmDialog(treeScroll, "Choose an item");
        if (result == ConfirmDialog.OK_OPTION) {
            System.out.println(tree.getSelectionPath());
        } else {
            System.out.println("User cancelled");
        }
    });
    JPanel p = new JPanel(new BorderLayout());
    p.add(b);
    p.setBorder(new EmptyBorder(50, 50, 50, 50));
    f.setContentPane(p);
    f.pack();
    f.setLocationByPlatform(true);
    f.setVisible(true);

}

From source file:DateTimeEditor.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent evt) {
            System.exit(0);//  w ww  .ja v a 2  s. com
        }
    });

    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(new EmptyBorder(5, 5, 5, 5));
    frame.setContentPane(panel);
    final DateTimeEditor field = new DateTimeEditor(DateTimeEditor.DATETIME, DateFormat.FULL);
    panel.add(field, "North");

    JPanel buttonBox = new JPanel(new GridLayout(2, 2));
    JButton showDateButton = new JButton("Show Date");
    buttonBox.add(showDateButton);

    final JComboBox timeDateChoice = new JComboBox();
    timeDateChoice.addItem("Time");
    timeDateChoice.addItem("Date");
    timeDateChoice.addItem("Date/Time");
    timeDateChoice.setSelectedIndex(2);
    timeDateChoice.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            field.setTimeOrDateType(timeDateChoice.getSelectedIndex());
        }
    });
    buttonBox.add(timeDateChoice);

    JButton toggleButton = new JButton("Toggle Enable");
    buttonBox.add(toggleButton);
    showDateButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.out.println(field.getDate());
        }
    });
    toggleButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            field.setEnabled(!field.isEnabled());
        }
    });
    panel.add(buttonBox, "South");

    final JComboBox lengthStyleChoice = new JComboBox();
    lengthStyleChoice.addItem("Full");
    lengthStyleChoice.addItem("Long");
    lengthStyleChoice.addItem("Medium");
    lengthStyleChoice.addItem("Short");
    lengthStyleChoice.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            field.setLengthStyle(lengthStyleChoice.getSelectedIndex());
        }
    });
    buttonBox.add(lengthStyleChoice);

    frame.pack();
    Dimension dim = frame.getToolkit().getScreenSize();
    frame.setLocation(dim.width / 2 - frame.getWidth() / 2, dim.height / 2 - frame.getHeight() / 2);
    frame.show();
}

From source file:Main.java

public static void main(String... args) {
    JPanel contentPane;/*from  ww w .ja va 2 s.c o  m*/
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    contentPane = new JPanel();
    contentPane.setLayout(new GridBagLayout());

    JPanel centerPanel = new JPanel();
    centerPanel.setOpaque(true);
    centerPanel.setBackground(Color.CYAN);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.FIRST_LINE_START;
    gbc.weightx = 1.0;
    gbc.weighty = 0.9;
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridwidth = 2;
    gbc.fill = GridBagConstraints.BOTH;

    contentPane.add(centerPanel, gbc);

    JButton leftButton = new JButton("Left");
    JButton rightButton = new JButton("Right");
    gbc.gridwidth = 1;
    gbc.gridy = 1;
    gbc.weightx = 0.3;
    gbc.weighty = 0.1;

    contentPane.add(leftButton, gbc);

    gbc.gridx = 1;
    gbc.weightx = 0.7;
    gbc.weighty = 0.1;

    contentPane.add(rightButton, gbc);

    frame.setContentPane(contentPane);
    frame.pack();
    frame.setLocationByPlatform(true);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String... args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel contentPane = new JPanel();

    JFormattedTextField ftf = new JFormattedTextField(NumberFormat.getNumberInstance());
    ftf.setColumns(10);/*from   w  ww.  j a v  a 2 s.co m*/
    ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
    ftf.setValue(100);
    lastValidValue = "100";
    ftf.addCaretListener(e -> {
        System.out.println("Last Valid Value : " + lastValidValue);
        if (ftf.isEditValid()) {
            String latestValue = ftf.getText();
            System.out.println("Latest Value : " + latestValue);
            if (!(latestValue.equals(lastValidValue)))
                ftf.setBackground(Color.YELLOW.darker());
            else {
                lastValidValue = ftf.getText();
                ftf.setBackground(Color.WHITE);
            }
        } else {
            System.out.println("Invalid Edit Entered.");
        }
    });
    contentPane.add(ftf);
    frame.setContentPane(contentPane);
    frame.pack();
    frame.setVisible(true);
}

From source file:com.music.Generator.java

public static void main(String[] args) throws Exception {
    Score score1 = new Score();
    Read.midi(score1, "c:/tmp/gen.midi");
    for (Part part : score1.getPartArray()) {
        System.out.println(part.getInstrument());
    }/*www . j a v a  2 s.c  om*/
    new StartupListener().contextInitialized(null);
    Generator generator = new Generator();
    generator.configLocation = "c:/config/music";
    generator.maxConcurrentGenerations = 5;
    generator.init();

    UserPreferences prefs = new UserPreferences();
    prefs.setElectronic(Ternary.YES);
    //prefs.setSimpleMotif(Ternary.YES);
    //prefs.setMood(Mood.MAJOR);
    //prefs.setDrums(Ternary.YES);
    //prefs.setClassical(true);
    prefs.setAccompaniment(Ternary.YES);
    prefs.setElectronic(Ternary.YES);
    final ScoreContext ctx = generator.generatePiece();
    Score score = ctx.getScore();
    for (Part part : score.getPartArray()) {
        System.out.println(part.getTitle() + ": " + part.getInstrument());
    }

    System.out.println("Metre: " + ctx.getMetre()[0] + "/" + ctx.getMetre()[1]);
    System.out.println(ctx);
    Write.midi(score, "c:/tmp/gen.midi");

    new Thread(new Runnable() {

        @Override
        public void run() {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setBounds(0, 0, 500, 500);
            frame.setVisible(true);
            Part part = ctx.getParts().get(PartType.MAIN);
            Note[] notes = part.getPhrase(0).getNoteArray();
            List<Integer> pitches = new ArrayList<Integer>();
            for (Note note : notes) {
                if (!note.isRest()) {
                    pitches.add(note.getPitch());
                }
            }
            GraphicsPanel gp = new GraphicsPanel(pitches);
            frame.setContentPane(gp);
        }
    }).start();

    DecimalFormat df = new DecimalFormat("#.##");

    for (Part part : score.getPartArray()) {
        StringBuilder sb = new StringBuilder();
        printStatistics(ctx, part);
        System.out.println("------------ " + part.getTitle() + "-----------------");
        Phrase[] phrases = part.getPhraseArray();
        for (Phrase phr : phrases) {
            if (phr instanceof ExtendedPhrase) {
                sb.append("Contour=" + ((ExtendedPhrase) phr).getContour() + " ");
            }
            double measureSize = 0;
            int measures = 0;
            double totalLength = 0;
            List<String> pitches = new ArrayList<String>();
            List<String> lengths = new ArrayList<String>();
            System.out.println("((Phrase notes: " + phr.getNoteArray().length + ")");
            for (Note note : phr.getNoteArray()) {
                if (!note.isRest()) {
                    int degree = 0;
                    if (phr instanceof ExtendedPhrase) {
                        degree = Arrays.binarySearch(((ExtendedPhrase) phr).getScale().getDefinition(),
                                note.getPitch() % 12);
                    }
                    pitches.add(String.valueOf(note.getPitch() + " (" + degree + ") "));
                } else {
                    pitches.add(" R ");
                }
                lengths.add(df.format(note.getRhythmValue()));
                measureSize += note.getRhythmValue();
                totalLength += note.getRhythmValue();
                ;
                if (measureSize >= ctx.getNormalizedMeasureSize()) {
                    pitches.add(" || ");
                    lengths.add(" || " + (measureSize > ctx.getNormalizedMeasureSize() ? "!" : ""));
                    measureSize = 0;
                    measures++;
                }
            }
            sb.append(pitches.toString() + "\r\n");
            sb.append(lengths.toString() + "\r\n");
            if (part.getTitle().equals(PartType.MAIN.getTitle())) {
                sb.append("\r\n");
            }
            System.out.println("Phrase measures: " + measures);
            System.out.println("Phrase length: " + totalLength);
        }
        System.out.println(sb.toString());
    }

    MutingPrintStream.ignore.set(true);
    Write.midi(score, "c:/tmp/gen.midi");
    MutingPrintStream.ignore.set(null);
    Play.midi(score);

    generator.toMp3(FileUtils.readFileToByteArray(new File("c:/tmp/gen.midi")));
}

From source file:lcmc.LCMC.java

/** The main function for starting the application. */
public static void main(final String[] args) {
    Tools.init();/*from w ww .j  a  v  a2s  .c o  m*/
    final JFrame mainFrame = new JFrame(Tools.getString("DrbdMC.Title") + " " + Tools.getRelease());
    final List<Image> il = new ArrayList<Image>();
    for (final String iconS : new String[] { "LCMC.AppIcon32", "LCMC.AppIcon48", "LCMC.AppIcon64",
            "LCMC.AppIcon128", "LCMC.AppIcon256" }) {
        il.add(Tools.createImageIcon(Tools.getDefault(iconS)).getImage());
    }
    mainFrame.setIconImages(il);
    final String autoArgs = initApp(args);
    mainFrame.setGlassPane(getMainGlassPane());
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.addWindowListener(new ExitListener());
    mainFrame.setJMenuBar(getMenuBar());
    mainFrame.setContentPane(getMainPanel());
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            createAndShowGUI((Container) mainFrame);
        }
    });
    if (autoArgs != null) {
        Tools.parseAutoArgs(autoArgs);
    }
    //final Thread t = new Thread(new Runnable() {
    //    public void run() {
    //        drbd.utilities.RoboTest.startMover(600000, true);
    //    }
    //});
    //t.start();
}

From source file:Main.java

public static void main(String... args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
    JTextField tfield1 = new JTextField(10);
    JTextField tfield2 = new JTextField(10);

    FocusListener tfieldListener = new FocusListener() {
        @Override//from  w  ww  . j  a  va 2  s .  c  o m
        public void focusGained(FocusEvent fe) {
        }

        @Override
        public void focusLost(FocusEvent fe) {
            String num1 = tfield1.getText().trim();
            String num2 = tfield2.getText().trim();
            if (num1 == null || num1.equals(""))
                num1 = "0";
            if (num2 == null || num2.equals(""))
                num2 = "0";
            System.out.println(Integer.toString(Integer.parseInt(num1) + Integer.parseInt(num2)));
        }
    };

    tfield1.addFocusListener(tfieldListener);
    tfield2.addFocusListener(tfieldListener);

    ((AbstractDocument) tfield1.getDocument()).setDocumentFilter(new MyDocumentFilter());
    ((AbstractDocument) tfield2.getDocument()).setDocumentFilter(new MyDocumentFilter());

    contentPane.add(tfield1);
    contentPane.add(tfield2);

    frame.setContentPane(contentPane);
    frame.pack();
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:ws.moor.bt.grapher.Grapher.java

public static void main(String[] args) throws IOException {
    if (args.length != 1) {
        System.err.println("Please specify a tab-separated values file");
        System.exit(1);// www .ja  va2  s. co  m
    }
    File file = new File(args[0]);
    final CSVMapCollector collector = new CSVMapCollector(
            new CSVSkipFilter(new CSVInputStream(new FileInputStream(file)), 0 * 1000));

    JFrame window = new JFrame("Grapher");
    window.setSize(1100, 800);
    window.setLayout(new BorderLayout());
    final ChartPanel chartPanel = new ChartPanel(null);

    List<String> possibleNames = collector.getAvailableStreams();
    Collections.sort(possibleNames);
    TreeNode root = convertToTree(possibleNames);

    final JTree tree = new JTree(root);
    tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            List<String> names = new ArrayList<String>();
            final TreePath[] paths = tree.getSelectionModel().getSelectionPaths();
            if (paths == null) {
                chartPanel.setChart(null);
                return;
            }
            for (TreePath path : paths) {
                Object lastPath = path.getLastPathComponent();
                if (lastPath instanceof DefaultMutableTreeNode) {
                    Object value = ((DefaultMutableTreeNode) lastPath).getUserObject();
                    if (value instanceof NodeValue) {
                        names.add(value.toString());
                    }
                }
            }
            chartPanel.setChart(createChart(collector, names.toArray(new String[names.size()])));
        }
    });
    Font font = tree.getFont();
    tree.setFont(font.deriveFont(10.0f));
    JScrollPane scrollPane = new JScrollPane(tree);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setLeftComponent(scrollPane);
    splitPane.setRightComponent(chartPanel);
    splitPane.setDividerLocation(200);

    window.setContentPane(splitPane);
    window.setVisible(true);
}

From source file:edu.ku.brc.specify.tools.StrLocalizerApp.java

/**
  * @param args/*from  w w w.  j  a va  2  s  . com*/
  */
public static void main(String[] args) {
    setAppName("Specify"); //$NON-NLS-1$
    System.setProperty(AppPreferences.factoryName, "edu.ku.brc.specify.config.AppPrefsDBIOIImpl"); // Needed by AppReferences //$NON-NLS-1$

    for (String s : args) {
        String[] pairs = s.split("="); //$NON-NLS-1$
        if (pairs.length == 2) {
            if (pairs[0].startsWith("-D")) //$NON-NLS-1$
            {
                //System.err.println("["+pairs[0].substring(2, pairs[0].length())+"]["+pairs[1]+"]");
                System.setProperty(pairs[0].substring(2, pairs[0].length()), pairs[1]);
            }
        } else {
            String symbol = pairs[0].substring(2, pairs[0].length());
            //System.err.println("["+symbol+"]");
            System.setProperty(symbol, symbol);
        }
    }

    // Now check the System Properties
    String appDir = System.getProperty("appdir");
    if (StringUtils.isNotEmpty(appDir)) {
        UIRegistry.setDefaultWorkingPath(appDir);
    }

    String appdatadir = System.getProperty("appdatadir");
    if (StringUtils.isNotEmpty(appdatadir)) {
        UIRegistry.setBaseAppDataDir(appdatadir);
    }

    // Then set this
    IconManager.setApplicationClass(Specify.class);
    IconManager.loadIcons(XMLHelper.getConfigDir("icons.xml")); //$NON-NLS-1$
    //ImageIcon icon = IconManager.getIcon("AppIcon", IconManager.IconSize.Std16);

    try {
        ResourceBundle.getBundle("resources", Locale.getDefault()); //$NON-NLS-1$

    } catch (MissingResourceException ex) {
        Locale.setDefault(Locale.ENGLISH);
        UIRegistry.setResourceLocale(Locale.ENGLISH);
    }

    try {
        if (!System.getProperty("os.name").equals("Mac OS X")) {
            UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
            PlasticLookAndFeel.setPlasticTheme(new DesertBlue());
        }
    } catch (Exception e) {
        //whatever
    }
    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    localPrefs.setDirPath(UIRegistry.getAppDataDir());

    boolean doIt = false;
    if (doIt)

    {
        Charset utf8charset = Charset.forName("UTF-8");
        Charset iso88591charset = Charset.forName("ISO-8859-1");

        ByteBuffer inputBuffer = ByteBuffer.wrap(new byte[] { (byte) 0xC3, (byte) 0xA2 });

        // decode UTF-8
        CharBuffer data = utf8charset.decode(inputBuffer);

        // encode ISO-8559-1
        ByteBuffer outputBuffer = iso88591charset.encode(data);
        byte[] outputData = outputBuffer.array();
        System.out.println(new String(outputData));
        return;
    }

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                UIHelper.OSTYPE osType = UIHelper.getOSType();
                if (osType == UIHelper.OSTYPE.Windows) {
                    UIManager.setLookAndFeel(new PlasticLookAndFeel());
                    PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());

                } else if (osType == UIHelper.OSTYPE.Linux) {
                    UIManager.setLookAndFeel(new PlasticLookAndFeel());
                }
            } catch (Exception e) {
                log.error("Can't change L&F: ", e); //$NON-NLS-1$
            }

            JFrame frame = new JFrame(getResourceString("StrLocalizerApp.AppTitle"));
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            final StrLocalizerApp sl = new StrLocalizerApp();
            sl.addMenuBar(frame);
            frame.setContentPane(sl);
            frame.setSize(768, 1024);

            //Dimension size = frame.getPreferredSize();
            //size.height = 500;
            //frame.setSize(size);
            frame.addWindowListener(sl);
            IconManager.setApplicationClass(Specify.class);
            frame.setIconImage(IconManager.getImage(IconManager.makeIconName("SpecifyWhite32")).getImage());
            UIHelper.centerAndShow(frame);

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    sl.startUp();
                }
            });
        }
    });
}