List of usage examples for javax.swing JFrame setContentPane
@BeanProperty(bound = false, hidden = true, description = "The client area of the frame where child components are normally inserted.") public void setContentPane(Container contentPane)
contentPane
property. From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 300);/*from w w w . j a va2 s .c o m*/ JPanel panel = new JPanel(new GridLayout(3, 1)); JLabel label = new JLabel(); JTextField tf = new JTextField(); JButton b = new JButton("calc sting width"); b.addActionListener(e -> { FontMetrics fm = label.getFontMetrics(label.getFont()); String text = tf.getText(); int textWidth = fm.stringWidth(text); label.setText("text width for \"" + text + "\": " + textWidth); }); panel.add(label); panel.add(tf); panel.add(b); frame.setContentPane(panel); 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(); contentPane.setOpaque(true);//from ww w . j a v a 2 s . co m contentPane.setBackground(Color.WHITE); contentPane.setLayout(null); JLabel label = new JLabel("This JPanel uses Absolute Positioning", JLabel.CENTER); label.setSize(300, 30); label.setLocation(5, 5); JButton button = new JButton("USELESS"); button.setSize(100, 30); button.setLocation(95, 45); contentPane.add(label); contentPane.add(button); frame.setContentPane(contentPane); frame.setSize(310, 125); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:de.mfo.jsurf.Main.java
/** * @param args/*from w ww . j a v a 2s . com*/ */ public static void main(String[] args) { String jsurf_filename = ""; Options options = new Options(); options.addOption("s", "size", true, "width (and height) of a image (default: " + size + ")"); options.addOption("q", "quality", true, "quality of the rendering: 0 (low), 1 (medium, default), 2 (high), 3 (extreme)"); options.addOption("o", "output", true, "output PNG into this file (- means standard output. Use ./- to denote a file literally named -.)"); CommandLineParser parser = new PosixParser(); HelpFormatter formatter = new HelpFormatter(); String cmd_line_syntax = "jsurf [options] jsurf_file"; String help_header = "jsurf is a renderer for algebraic surfaces. If - is specified as a filename the jsurf file is read from standard input. " + "Use ./- to denote a file literally named -."; String help_footer = ""; try { CommandLine cmd = parser.parse(options, args); if (cmd.getArgs().length > 0) jsurf_filename = cmd.getArgs()[0]; else { formatter.printHelp(cmd_line_syntax, help_header, options, help_footer); return; } if (cmd.hasOption("output")) { } if (cmd.hasOption("size")) size = Integer.parseInt(cmd.getOptionValue("size")); int quality = 1; if (cmd.hasOption("quality")) quality = Integer.parseInt(cmd.getOptionValue("quality")); switch (quality) { case 0: aam = AntiAliasingMode.ADAPTIVE_SUPERSAMPLING; aap = AntiAliasingPattern.OG_1x1; break; case 2: aam = AntiAliasingMode.ADAPTIVE_SUPERSAMPLING; aap = AntiAliasingPattern.OG_4x4; break; case 3: aam = AntiAliasingMode.SUPERSAMPLING; aap = AntiAliasingPattern.OG_4x4; break; case 1: aam = AntiAliasingMode.ADAPTIVE_SUPERSAMPLING; aap = AntiAliasingPattern.QUINCUNX; } } catch (ParseException exp) { System.out.println("Unexpected exception:" + exp.getMessage()); System.exit(-1); } catch (NumberFormatException nfe) { formatter.printHelp(cmd_line_syntax, help_header, options, help_footer); System.exit(-1); } final Properties jsurf = new Properties(); try { if (jsurf_filename.equals("-")) jsurf.load(System.in); else jsurf.load(new FileReader(jsurf_filename)); FileFormat.load(jsurf, asr); } catch (Exception e) { System.err.println("Unable to read jsurf file " + jsurf_filename); e.printStackTrace(); System.exit(-2); } asr.setAntiAliasingMode(aam); asr.setAntiAliasingPattern(aap); // display the image in a window final String window_title = "jsurf: " + jsurf_filename; SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame f = new JFrame(window_title); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSurferRenderPanel p = null; try { p = new JSurferRenderPanel(jsurf); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } f.setContentPane(p); // f.getContentPane().add( new JLabel( new ImageIcon( window_image ) ) ); f.pack(); // f.setResizable( false ); f.setVisible(true); } }); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane pane = new JTextPane(); pane.setEditorKit(new CustomEditorKit()); pane.setText("Underline With Different Color"); StyledDocument doc = (StyledDocument) pane.getDocument(); MutableAttributeSet attrs = new SimpleAttributeSet(); attrs.addAttribute("Underline-Color", Color.red); doc.setCharacterAttributes(0, doc.getLength() - 1, attrs, true); JScrollPane sp = new JScrollPane(pane); frame.setContentPane(sp); frame.setPreferredSize(new Dimension(400, 300)); frame.pack();/*from w w w. j a va2 s .c o m*/ frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:edu.ku.brc.specify.toycode.UpdatesApp.java
/** * @param args//w ww. j a v a 2 s. c o m */ public static void main(String[] args) { if (args.length == 9) { for (int i = 0; i < args.length; i++) { System.out.println(i + "=" + args[i]); } doingCmdLine = true; UpdatesApp updateApp = new UpdatesApp(); try { updateApp.merge(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]); } catch (java.lang.NullPointerException ex) { System.err.println("****The merge process failed: check for errors above."); } } else { SwingUtilities.invokeLater(new Runnable() { public void run() { try { UIHelper.OSTYPE osType = UIHelper.getOSType(); if (osType == UIHelper.OSTYPE.Windows) { //UIManager.setLookAndFeel(new WindowsLookAndFeel()); UIManager.setLookAndFeel(new PlasticLookAndFeel()); PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue()); } else if (osType == UIHelper.OSTYPE.Linux) { //UIManager.setLookAndFeel(new GTKLookAndFeel()); UIManager.setLookAndFeel(new PlasticLookAndFeel()); //PlasticLookAndFeel.setPlasticTheme(new SkyKrupp()); //PlasticLookAndFeel.setPlasticTheme(new DesertBlue()); //PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue()); //PlasticLookAndFeel.setPlasticTheme(new DesertGreen()); } } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(UpdatesApp.class, e); System.err.println("Can't change L&F: " + e); //$NON-NLS-1$ } UpdatesApp panel = new UpdatesApp(); JFrame frame = new JFrame(); frame.setTitle("Install4J XML Updater"); frame.setContentPane(panel); JMenuBar menuBar = panel.createMenus(); if (menuBar != null) { //top.add(menuBar, BorderLayout.NORTH); frame.setJMenuBar(menuBar); } frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }); } }
From source file:com.limegroup.gnutella.gui.notify.AnimatedWindow.java
public static void main(String[] args) { JPanel content = new JPanel(new BorderLayout()); content.setBorder(BorderFactory.createLineBorder(Color.black, 2)); JLabel label = new JLabel("Hello World"); label.setIcon(UIManager.getIcon("FileView.computerIcon")); label.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); content.add(label, BorderLayout.CENTER); final AnimatedWindow window = new AnimatedWindow(null); window.setFinalLocation(new Point(200, 200)); window.setContentPane(content);//from w ww . ja va 2 s. c o m JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 10)); JButton button = new JButton("Bottom -> Top"); buttonPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { window.setMode(AnimationMode.BOTTOM_TO_TOP); if (!window.isVisible() || window.isHideAnimationInProgress()) { window.doShow(); } else { window.doHide(); } } }); button = new JButton("Top -> Bottom"); buttonPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { window.setMode(AnimationMode.TOP_TO_BOTTOM); if (!window.isVisible() || window.isHideAnimationInProgress()) { window.doShow(); } else { window.doHide(); } } }); button = new JButton("Fade"); buttonPanel.add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { window.setMode(AnimationMode.FADE); if (!window.isVisible() || window.isHideAnimationInProgress()) { window.doShow(); } else { window.doHide(); } } }); JFrame app = new JFrame("AnimatedWindow Demo"); app.setContentPane(buttonPanel); app.pack(); app.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); app.setVisible(true); }
From source file:customize.swing.startMain.java
public static void main(String[] args) { JFrame frame = new JFrame("startMain"); frame.setContentPane(new startMain().panel1); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack();/*from w w w . jav a 2 s .c o m*/ frame.setVisible(true); frame.setBounds(500, 300, 983, 587); }
From source file:ca.sqlpower.wabit.swingui.enterprise.UserPanel.java
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { WabitWorkspace p = new WabitWorkspace(); p.setUUID("system"); // Add data sources to workspace DataSourceCollection<SPDataSource> plini = new PlDotIni(); plini.read(new File(System.getProperty("user.home"), "pl.ini")); List<SPDataSource> dataSources = plini.getConnections(); for (int i = 0; i < 10 && i < dataSources.size(); i++) { p.addDataSource(new WabitDataSource(dataSources.get(i))); }/*from www .java2 s . c o m*/ // Add layouts to workspace Report layout = new Report("Example Layout"); p.addReport(layout); Page page = layout.getPage(); page.addContentBox(new ContentBox()); page.addGuide(new Guide(Axis.HORIZONTAL, 123)); page.addContentBox(new ContentBox()); // dd a report task ReportTask task = new ReportTask(); task.setReport(layout); p.addReportTask(task); User user = new User("admin", "admin"); user.setParent(p); Group group = new Group("Admins"); group.setParent(p); group.addMember(new GroupMember(user)); Group group2 = new Group("Other Group"); group2.setParent(p); p.addUser(user); p.addGroup(group); p.addGroup(group2); UserPanel panel = new UserPanel(user); UserPanel panel2 = new UserPanel(user); JFrame f = new JFrame("TEST PANEL"); JPanel outerPanel = new JPanel(new BorderLayout()); outerPanel.setBorder(BorderFactory.createLineBorder(Color.BLUE)); outerPanel.add(panel.getPanel(), BorderLayout.CENTER); f.setContentPane(outerPanel); f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); JFrame f2 = new JFrame("TEST PANEL"); JPanel outerPanel2 = new JPanel(new BorderLayout()); outerPanel2.setBorder(BorderFactory.createLineBorder(Color.BLUE)); outerPanel2.add(panel2.getPanel(), BorderLayout.CENTER); f2.setContentPane(outerPanel2); f2.pack(); f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f2.setVisible(true); } catch (Exception ex) { throw new RuntimeException(ex); } } }); }
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 GridLayout(1, 2, 2, 2)); JTextArea tArea1 = new JTextArea(); tArea1.setLineWrap(true);/*from www. j av a 2 s . c o m*/ JTextArea tArea2 = new JTextArea(); tArea2.setLineWrap(true); tArea1.setText("I got a long long line of text in my JTextArea"); tArea2.setText("I got a long long line of text in my JTextArea"); JScrollPane scroller1 = new JScrollPane(); JScrollPane scroller2 = new JScrollPane(); scroller1.setViewportView(tArea1); scroller2.setViewportView(tArea2); contentPane.add(scroller1); contentPane.add(scroller2); frame.setContentPane(contentPane); frame.setSize(100, 100); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] a) { final JFrame jf = new JFrame("JIFrameDemo Main Window"); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); screenSize.width -= 42;/*from ww w . j a v a2 s .c o m*/ screenSize.height -= 42; jf.setSize(screenSize); jf.setLocation(20, 20); JMenuBar mb = new JMenuBar(); jf.setJMenuBar(mb); JMenu fm = new JMenu("File"); mb.add(fm); JMenuItem mi; fm.add(mi = new JMenuItem("Exit")); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); JDesktopPane dtp = new JDesktopPane(); //dtp.setBackground(Color.GREEN); jf.setContentPane(dtp); JInternalFrame mboxFrame = new JInternalFrame("Mail Reader", true, true, true, true); JLabel reader = new JLabel("Mail Reader Would Be Here"); mboxFrame.setContentPane(reader); mboxFrame.setSize(400, 300); mboxFrame.setLocation(50, 50); mboxFrame.setVisible(true); dtp.add(mboxFrame); JInternalFrame compFrame = new JInternalFrame("Compose Mail", true, true, true, true); JLabel composer = new JLabel("Mail Compose Would Be Here"); compFrame.setContentPane(composer); compFrame.setSize(300, 200); compFrame.setLocation(200, 200); compFrame.setVisible(true); dtp.add(compFrame); JInternalFrame listFrame = new JInternalFrame("Users", true, true, true, true); JLabel list = new JLabel("List of Users Would Be Here"); listFrame.setContentPane(list); listFrame.setLocation(400, 400); listFrame.setSize(500, 200); listFrame.setVisible(true); dtp.add(listFrame); jf.setVisible(true); jf.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { jf.setVisible(false); jf.dispose(); System.exit(0); } }); }