List of usage examples for javax.swing JFrame add
public Component add(String name, Component comp)
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JLabel("Hit Escape to exit full screen", JLabel.CENTER), BorderLayout.CENTER); frame.setSize(300, 300);/* w ww . j ava 2 s . c om*/ KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke("ESCAPE"); Action escapeAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .setFullScreenWindow(null); } }; frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE"); frame.getRootPane().getActionMap().put("ESCAPE", escapeAction); GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame); }
From source file:SparseTableModel.java
public static void main(String[] a) { String headers[] = { "A", "B" }; TableModel model = new SparseTableModel(10, headers); JTable table = new JTable(model); model.setValueAt("1", 0, 0); model.setValueAt("2", 9, 0); model.setValueAt("3", 5, 1); model.setValueAt("4", 8, 1); JFrame frame = new JFrame("Fixed Column Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(table), BorderLayout.CENTER); frame.setSize(300, 150);/*from w ww .j av a 2 s . c o m*/ frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField nameTextField = new JTextField(); frame.add(nameTextField, BorderLayout.NORTH); FileReader reader = null;/*w w w.j av a 2 s. c o m*/ try { reader = new FileReader("fileName.txt"); nameTextField.read(reader, "fileName.txt"); } catch (IOException exception) { System.err.println("Load oops"); exception.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException exception) { System.err.println("Error closing reader"); exception.printStackTrace(); } } } frame.setSize(250, 100); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField nameTextField = new JTextField(); frame.add(nameTextField, BorderLayout.NORTH); FileWriter writer = null;//from w w w .j av a 2s. c om try { writer = new FileWriter("filename.txt"); nameTextField.write(writer); } catch (IOException exception) { System.err.println("Save oops"); exception.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (IOException exception) { System.err.println("Error closing writer"); exception.printStackTrace(); } } } frame.setSize(250, 100); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { int cp = 0;//from ww w . j a v a 2s .c o m StyledDocument doc; JTextPane jta = new JTextPane(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); doc = jta.getStyledDocument(); JScrollPane jsp = new JScrollPane(jta); jsp.setPreferredSize(new Dimension(400, 400)); String[] fnt = ge.getAvailableFontFamilyNames(); MutableAttributeSet mas = jta.getInputAttributes(); for (int i = 0; i < fnt.length; i++) { StyleConstants.setBold(mas, false); StyleConstants.setItalic(mas, false); StyleConstants.setFontFamily(mas, fnt[i]); StyleConstants.setFontSize(mas, 16); doc.insertString(cp, fnt[i] + "\n", mas); StyleConstants.setBold(mas, true); doc.insertString(cp, fnt[i] + "bold \n", mas); StyleConstants.setItalic(mas, true); doc.insertString(cp, fnt[i] + "bold and italic\n", mas); StyleConstants.setBold(mas, false); doc.insertString(cp, fnt[i] + "italic\n", mas); } JFrame frm = new JFrame(); frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frm.setLayout(new BorderLayout()); frm.add(jsp, BorderLayout.CENTER); frm.setLocation(100, 100); frm.pack(); frm.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame f = new JFrame("JTree Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); JScrollPane scrollPane = new JScrollPane(tree); f.add(scrollPane, BorderLayout.CENTER); f.setSize(300, 200);/*from w ww . ja v a 2 s. c o m*/ f.setVisible(true); }
From source file:SelectingComboSample.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F" }; JFrame frame = new JFrame("Selecting JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox comboBox = new JComboBox(labels); frame.add(comboBox, BorderLayout.SOUTH); JComboBox.KeySelectionManager manager = new JComboBox.KeySelectionManager() { public int selectionForKey(char aKey, ComboBoxModel aModel) { System.out.println(aKey); return -1; }/*w ww .jav a 2 s . c o m*/ }; comboBox.setKeySelectionManager(manager); frame.setSize(400, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField nameTextField = new JTextField(); frame.add(nameTextField, BorderLayout.NORTH); frame.add(new JTextField(), BorderLayout.SOUTH); InputVerifier verifier = new InputVerifier() { public boolean verify(JComponent input) { final JTextComponent source = (JTextComponent) input; String text = source.getText(); if ((text.length() != 0) && !(text.equals("Exit"))) { JOptionPane.showMessageDialog(source, "Can't leave.", "Error Dialog", JOptionPane.ERROR_MESSAGE); return false; } else { return true; }//from w w w .j a v a 2 s . c o m } }; nameTextField.setInputVerifier(verifier); frame.setSize(250, 100); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { String name = "http://urlWithClassName"; try {//from w ww. j a va 2 s. c o m if (!name.endsWith(".class")) { System.err.println("That doesn't look like a byte code file!"); return; } URL u = new URL(name); URLClassLoader ucl = new URLClassLoader(u); // parse out the name of the class from the URL String s = u.getFile(); String classname = s.substring(s.lastIndexOf('/'), s.lastIndexOf(".class")); Class AppletClass = ucl.loadClass(classname, true); Applet apl = (Applet) AppletClass.newInstance(); JFrame f = new JFrame(); f.setSize(200, 200); f.add("Center", apl); apl.init(); apl.start(); f.setVisible(true); } catch (Exception e) { System.err.println(e); } }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JCheckBox checkBox = new JCheckBox("A"); checkBox.setToolTipText("Italic font"); frame.add(checkBox, BorderLayout.NORTH); frame.setSize(300, 100);/*from w ww .j a va 2 s. c om*/ frame.setVisible(true); }