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:umontreal.iro.lecuyer.charts.ScatterChart.java
/** * Displays chart on the screen using Swing. * This method creates an application containing a chart panel displaying * the chart. The created frame is positioned on-screen, and displayed before * it is returned. The <TT>width</TT> and the <TT>height</TT> * of the chart are measured in pixels. * /*from w w w.j a va 2s . c o m*/ * @param width frame width in pixels. * * @param height frame height in pixels. * * @return frame containing the chart.; * */ public JFrame view(int width, int height) { JFrame myFrame; if (chart.getTitle() != null) myFrame = new JFrame("ScatterChart from SSJ: " + chart.getTitle().getText()); else myFrame = new JFrame("ScatterChart from SSJ"); XYPlot plot = chart.getXYPlot(); /* // The drawn points are somewhat big, of different shapes, unfilled XYLineAndShapeRenderer shape = new XYLineAndShapeRenderer(false, true); int nb = getSeriesCollection().getSeriesCollection().getSeriesCount(); for (int i = 0 ; i < nb ; i++) { shape.setSeriesShapesFilled(i, false); plot.setRenderer(i, shape); } */ // The drawn points are all square, filled XYDotRenderer shape = new XYDotRenderer(); final int dotSize = 3; shape.setDotWidth(dotSize); shape.setDotHeight(dotSize); int nb = getSeriesCollection().getSeriesCollection().getSeriesCount(); for (int i = 0; i < nb; i++) plot.setRenderer(i, shape); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(width, height)); myFrame.setContentPane(chartPanel); myFrame.pack(); myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); myFrame.setLocationRelativeTo(null); myFrame.setVisible(true); return myFrame; }
From source file:edu.snu.leader.discrete.simulator.SimulatorLauncherGUI.java
JFrame createJFrameErrorMessages(ErrorPacketContainer errorPackets, JTabbedPane theTabbedPane) { JFrame errorMessages = new JFrame(); JPanel errorMessagesContentPane = new JPanel(); errorMessages.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); errorMessages.setTitle("Error Messages"); errorMessages.setBounds(this.getX() + this.getWidth() + 5, this.getY(), 350, 300); errorMessagesContentPane = new JPanel(); errorMessagesContentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); errorMessagesContentPane.setLayout(new BorderLayout(0, 0)); errorMessages.setContentPane(errorMessagesContentPane); JPanel panel = new JPanel(); errorMessagesContentPane.add(panel, BorderLayout.NORTH); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); for (int i = 0; i < errorPackets.errorMessages.size(); i++) { JTextPane temp = createErrorPane(errorPackets.errorMessages.get(i), errorPackets.erroredComponents.get(i), theTabbedPane, errorPackets.tabIndexes.get(i)); panel.add(temp);/*from www. j a v a2 s .co m*/ } return errorMessages; }
From source file:levelBuilder.DialogMaker.java
/** * Provides instructions for using the program. *//*from w w w.ja va2s . com*/ private static void instructionsWindow() { JFrame frame = new JFrame("Instructions"); JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0)); panel.add(new JLabel("DO NOT USE THE RIGHT CLICK MENU.", SwingConstants.LEFT)); panel.add(new JLabel("DO NOT REMOVE NODES OR VERTICES WITH THIS GUI. EDIT THE XML FILE INSTEAD.", SwingConstants.LEFT)); panel.add(new JLabel("", SwingConstants.LEFT)); panel.add( new JLabel("The 'Check' button runs various checks to make sure the graph does not contain errors.", SwingConstants.LEFT)); panel.add(new JLabel("", SwingConstants.LEFT)); panel.add(new JLabel("Transforming mode:", SwingConstants.LEFT)); panel.add(new JLabel("Shift + click + drag to rotate", SwingConstants.LEFT)); panel.add(new JLabel("Scroll to zoom", SwingConstants.LEFT)); panel.add(new JLabel("Command + click + drag to to weird stretchy thing", SwingConstants.LEFT)); panel.add(new JLabel("", SwingConstants.LEFT)); panel.add(new JLabel("Picking mode:", SwingConstants.LEFT)); panel.add(new JLabel("Click + drag to select multiple nodes", SwingConstants.LEFT)); panel.add(new JLabel("Click + drag moves node or group of nodes", SwingConstants.LEFT)); panel.add(new JLabel("Only in picking mode can you see different strategies", SwingConstants.LEFT)); panel.add(new JLabel("New strategies will also only appear after refocusing on the main window", SwingConstants.LEFT)); panel.add(new JLabel("", SwingConstants.LEFT)); panel.add(new JLabel("Editing mode:", SwingConstants.LEFT)); panel.add(new JLabel("Click + drag from one node to another creates an edge", SwingConstants.LEFT)); panel.add(new JLabel("After drawing a new edge you have to click the 'new edge' button", SwingConstants.LEFT)); panel.add(new JLabel("Click to add a new node", SwingConstants.LEFT)); panel.setOpaque(true); frame.setContentPane(panel); frame.pack(); frame.setLocation(windowWidth, verticalWindowPlacement); frame.setVisible(true); verticalWindowPlacement += frame.getBounds().height; }
From source file:charts.Chart.java
public static void LineChart(DefaultCategoryDataset dataset, String title, String x_axis_label, String y_axis_label, boolean showlegend, float maxvalue, float minvalue) { JFrame chartwindow = new JFrame(title); JFreeChart jfreechart = ChartFactory.createLineChart(title, x_axis_label, y_axis_label, dataset, PlotOrientation.VERTICAL, showlegend, // include legend true, // tooltips true // urls );/*from w ww . j a va 2 s.com*/ CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot(); categoryplot.setBackgroundPaint(Color.white); categoryplot.setRangeGridlinePaint(Color.black); NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); numberaxis.setStandardTickUnits(NumberAxis.createStandardTickUnits()); CategoryPlot plot = (CategoryPlot) jfreechart.getPlot(); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); if (minvalue == 0 && maxvalue == 0) { rangeAxis.setAutoRangeIncludesZero(true); } else { rangeAxis.setRange(minvalue, maxvalue); } LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer(); lineandshaperenderer.setBaseStroke(new BasicStroke(2.0f)); lineandshaperenderer.setShapesVisible(true); lineandshaperenderer.setDrawOutlines(true); lineandshaperenderer.setUseFillPaint(true); lineandshaperenderer.setFillPaint(Color.white); //GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.MAGENTA, 0.0f, 0.0f, Color.MAGENTA); //lineandshaperenderer.setSeriesPaint(0, gp1); //ou lineandshaperenderer.setSeriesPaint(0, Color.RED); JPanel jpanel = new ChartPanel(jfreechart); jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight)); chartwindow.setContentPane(jpanel); chartwindow.pack(); RefineryUtilities.centerFrameOnScreen(chartwindow); chartwindow.setVisible(true); }
From source file:ucar.unidata.idv.flythrough.ChartDecorator.java
/** * _more_/*from ww w. j ava 2s.c om*/ * * @param g2 _more_ * @param comp _more_ * * @return _more_ */ public boolean paintDashboard(Graphics2D g2, JComponent comp) { try { List<SampleInfo> infos = new ArrayList<SampleInfo>(sampleInfos); if (infos.size() == 0) { return false; } Rectangle b = comp.getBounds(); JFrame dummyFrame = new JFrame(""); XYSeriesCollection dataset = new XYSeriesCollection(); JFreeChart chart = Flythrough.createChart(dataset); XYPlot xyPlot = (XYPlot) chart.getPlot(); int chartHeight = b.height - flythrough.getDashboardImage().getHeight(null); chartHeight = Math.max(chartHeight, 50); int chartWidth = Math.min(chartHeight * 4, b.width); int dx = b.width / 2 - chartWidth / 2; int dy = 0; Image lastImage = lastChartImage; if ((lastImage != null) && (lastImage.getWidth(null) == chartWidth) && (lastImage.getHeight(null) == chartHeight)) { g2.translate(dx, dy); g2.drawImage(lastImage, 0, 0, null); g2.translate(-dx, -dy); return false; } for (int i = 0; i < infos.size(); i++) { SampleInfo info = infos.get(i); ValueAxis rangeAxis = new NumberAxis(info.getName()); if (info.getRange() != null) { rangeAxis .setRange(new org.jfree.data.Range(info.getRange().getMin(), info.getRange().getMax())); } dataset = new XYSeriesCollection(); dataset.addSeries(info.getSeries()); xyPlot.setRangeAxis(i, rangeAxis, false); xyPlot.setDataset(i, dataset); xyPlot.mapDatasetToRangeAxis(i, i); final Color color = COLORS[i % COLORS.length]; XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { public Paint xgetItemPaint(final int row, final int column) { return color; } }; renderer.setSeriesPaint(0, color); xyPlot.setRenderer(i, renderer); } ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(chartWidth, chartHeight)); dummyFrame.setContentPane(chartPanel); dummyFrame.pack(); Image image = ImageUtils.getImage(chartPanel); lastChartImage = image; g2.translate(dx, dy); g2.drawImage(image, 0, 0, null); g2.translate(-dx, -dy); } catch (Exception exc) { logException("Painting chart", exc); } return false; }
From source file:charts.Chart.java
public static void GraficoSeries() { //System.out.println("After initComponents"); JFrame janela = new JFrame("Example of the series graphic"); janela.getContentPane().setLayout(null); javax.swing.JLabel jLabel1 = new javax.swing.JLabel(); jLabel1.setText(""); janela.getContentPane().add(jLabel1); y_of_x = new double[n_points]; x = new double[n_points]; XYSeries series1 = new XYSeries("Cos(x) versus x"); XYSeries series2 = new XYSeries("Cos^2(x) versus x"); for (int i = 0; i < n_points; i++) {//calculate the data to be plotted y_of_x[i] = Math.cos(i * Math.PI / 180); series1.add((double) i, y_of_x[i]);//add values to the series series2.add((double) i, Math.pow(y_of_x[i], 2)); }/*from w ww . jav a 2 s .c o m*/ XYDataset dataset1 = new XYSeriesCollection(series1); XYDataset dataset2 = new XYSeriesCollection(series2); CombinedDomainXYPlot parent = new CombinedDomainXYPlot(new NumberAxis("x-angle argument")); XYItemRenderer renderer1 = new StandardXYItemRenderer(); XYPlot subplot1 = new XYPlot(dataset1, null, new NumberAxis("Cos(x)"), renderer1); NumberAxis axis1 = (NumberAxis) subplot1.getRangeAxis(); axis1.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 10)); axis1.setLabelFont(new Font("SansSerif", Font.PLAIN, 10)); axis1.setAutoRangeIncludesZero(false); parent.add(subplot1, 1); XYItemRenderer renderer2 = new StandardXYItemRenderer(); XYPlot subplot2 = new XYPlot(dataset2, null, new NumberAxis("Cos^2(x)"), renderer2); NumberAxis axis2 = (NumberAxis) subplot2.getRangeAxis(); axis2.setTickLabelFont(new Font("Monospaced", Font.PLAIN, 10)); axis2.setLabelFont(new Font("SansSerif", Font.PLAIN, 10)); axis2.setAutoRangeIncludesZero(false); parent.add(subplot2, 1); JFreeChart chart = new JFreeChart("Cos(x) versus x", parent); ChartPanel myChart = new ChartPanel(chart); janela.setSize(500, 600); janela.setContentPane(myChart); janela.setVisible(true); }
From source file:GUI.PizzaCat.java
/** * Create the GUI and show it. As with all GUI code, this must run on the * event-dispatching thread.//from w ww . ja va2 s. c om */ public void createAndShowGUI() { // Create and set up the window. //new PizzaCat().setVisible(true); JFrame frame = new JFrame("Processing Results"); frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); // Create and set up the content pane. JComponent newContentPane = new ProgressBarDemo(); newContentPane.setOpaque(true); // content panes must be opaque frame.setContentPane(newContentPane); // Display the window. frame.pack(); frame.setVisible(true); }
From source file:Interface.Stats.java
/** * * @param f /* w ww.ja va 2 s .c om*/ */ private Stats(JFrame f) { // On initialise les boutons JButton valider = new JButton("Valider"); JButton retour = new JButton("Retour"); JComboBox combo = new JComboBox(); // On initialise et remplit la combobox combo.setPreferredSize(new Dimension(400, 30)); combo.addItem("Nombre de patient par service"); combo.addItem("Salaire moyen des employs"); combo.addItem("Nombre d'intervention par mdecin"); // On initialise les JLabels JLabel texte = new JLabel("Veuillez selectionner la requete envoyer"); // On change le bouton de forme valider.setPreferredSize(new Dimension(200, 30)); valider.setOpaque(false); retour.setPreferredSize(new Dimension(200, 30)); retour.setOpaque(false); // On initialise les Jpanels p1 = new JPanel(); p1.setPreferredSize(new Dimension(600, 100)); p1.add(texte); p1.setOpaque(false); p2 = new JPanel(); p2.add(combo); p2.setOpaque(false); p4 = new JPanel(); p4.add(retour); p4.add(valider); p4.setOpaque(false); // Gestion des boutons retour.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Accueil.getFenetre(f); } }); valider.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (combo.getSelectedItem().equals("Nombre de patient par service")) { System.out.println( "Nb de patients en REA : " + Connexion.getInstance().nb_malade_services("\"REA\"")); System.out.println( "Nb de patients en ORL : " + Connexion.getInstance().nb_malade_services("\"ORL\"")); System.out.println( "Nb de patients en CHG : " + Connexion.getInstance().nb_malade_services("\"CHG\"")); // new Camembert(f, Connexion.getInstance().nb_malade_services("\"REA\""), Connexion.getInstance().nb_malade_services("\"ORL\""), Connexion.getInstance().nb_malade_services("\"CHG\"")); JPanel panel_camemb = Camembert.cCamembert(f, Connexion.getInstance().nb_malade_services("\"REA\""), Connexion.getInstance().nb_malade_services("\"ORL\""), Connexion.getInstance().nb_malade_services("\"CHG\"")); ; f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background f.add(p1); f.add(p2); f.add(p4); f.add(panel_camemb); f.setVisible(true); } else if (combo.getSelectedItem().equals("Salaire moyen des employs")) { JLabel jf_doc, jf_inf, jf_emp; JTextField jtf_doc, jtf_inf, jtf_emp; JPanel p5, p6, p7; // On initialise les JF jf_doc = new JLabel("Salaire moyen des docteurs"); jf_inf = new JLabel("Salaire moyen des infirmiers"); jf_emp = new JLabel("Salaire moyen de tous les employs"); // On initialise les JTF jtf_doc = new JTextField(); jtf_doc.setPreferredSize(new Dimension(200, 30)); jtf_doc.setText(Float.toString(Connexion.getInstance().moyenne_salaired()) + " "); jtf_inf = new JTextField(); jtf_inf.setPreferredSize(new Dimension(200, 30)); jtf_inf.setText(Float.toString((Connexion.getInstance().moyenne_salairei())) + " "); jtf_emp = new JTextField(); jtf_emp.setPreferredSize(new Dimension(160, 30)); jtf_emp.setText(Float.toString((Connexion.getInstance().moyenne_salaire())) + " "); // On cre les JPanels p5 = new JPanel(); p5.add(jf_doc); p5.add(jtf_doc); p5.setOpaque(false); p6 = new JPanel(); p6.add(jf_inf); p6.add(jtf_inf); p6.setOpaque(false); p7 = new JPanel(); p7.add(jf_emp); p7.add(jtf_emp); p7.setOpaque(false); f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background f.add(p1); f.add(p2); f.add(p4); f.add(p5); f.add(p6); f.add(p7); f.setVisible(true); f.setSize(new Dimension(600, 600)); } else if (combo.getSelectedItem().equals("Nombre d'intervention par mdecin")) { ArrayList liste = null; try { // ICI !!!!!!!!!! liste = Connexion.getInstance().reporting( "SELECT e.nom , COUNT(d.no_docteur) FROM hospitalisation h, docteur d , employe e WHERE (h.no_docteur= d.no_docteur) AND e.no_employe = d.no_docteur GROUP BY e.nom"); } catch (SQLException ex) { Logger.getLogger(Stats.class.getName()).log(Level.SEVERE, null, ex); } if (liste != null) { JPanel panel_camemb = Camembert.cCamembert(f, liste); f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background f.add(p1); f.add(p2); f.add(p4); f.add(panel_camemb); f.setVisible(true); } } } }); }
From source file:citation_prediction.CitationCore.java
/** * This function will take a list of WSB solutions and graph them. You can add solutions to the graph by saving * the return of the function the first time and passing it back in on the next call as the 'plot'. * /*from w ww .j a v a2 s .c om*/ * * @param data_in_days The citation data distributed mostly even in days (call fixdata function if data is in years). * @param m The average number of new references in each new paper for a journal. * @param plot The plot you would like the WSB solution plotted to. * @param graphTitle The title to display on the JPanel. * @param lineLegend The title of this curve. * @param wsbSolutions The list of WSB solutions to graph. * @param showGraph Display the graph to the user (generally called once all curves have been added.) * @param frame The frame to display the graph in. * @return A Panel containing the graph. */ public Plot2DPanel graphWSB(double[][] data_in_days, double m, Plot2DPanel plot, String graphTitle, String lineLegend, ArrayList<LinkedHashMap<String, Double>> wsbSolutions, boolean showGraph, JFrame frame) { //source of library: http://code.google.com/p/jmathplot/ int plotLength = data_in_days.length + (365 * 3); double[][] data_in_years = new double[plotLength][2]; //Translate the data into years instead of days for (int i = 0; i < data_in_days.length; i++) { data_in_years[i][0] = data_in_days[i][0] / 365; data_in_years[i][1] = data_in_days[i][1]; } for (int i = data_in_days.length; i < plotLength; i++) { data_in_years[i][0] = data_in_years[i - 1][0] + .025; data_in_years[i][1] = data_in_years[data_in_days.length - 1][1]; } if (plot == null) { plot = new Plot2DPanel(); plot.addScatterPlot("Actual Citations", data_in_years); //Plot the data } //Extract the timevalue column RealMatrix mdata = MatrixUtils.createRealMatrix(data_in_years); double[] tvalues = mdata.getColumn(0); double[] cvalues = new double[plotLength]; for (LinkedHashMap<String, Double> s : wsbSolutions) { //calculate their fitted y values for (int i = 0; i < plotLength; i++) { cvalues[i] = m * (Math.exp( s.get("lambda") * pnorm((Math.log(365 * tvalues[i]) - s.get("mu")) / s.get("sigma"))) - 1); } //Calculate the Ultimate Impact double c_impact = m * (Math.exp(s.get("lambda")) - 1); //plot the fit plot.addLinePlot("Ultimate Impact=" + c_impact + " :: " + lineLegend, tvalues, cvalues); } // put the PlotPanel in a JFrame, as a JPanel if (showGraph) { plot.setAxisLabel(0, "Time in Years"); plot.setAxisLabel(1, "Cumulative Citations"); //Uncomment these if you wish to have fixed axis. //plot.setFixedBounds(1, 0, 500); //plot.setFixedBounds(0, 0, 60); // Add the file Title BaseLabel filetitle = new BaseLabel(graphTitle, Color.GRAY, 0.5, 1.1); filetitle.setFont(new Font("Courier", Font.BOLD, 13)); plot.addPlotable(filetitle); plot.addLegend("SOUTH"); //JFrame frame = new JFrame(graphTitle); frame.setTitle(graphTitle); frame.setContentPane(plot); frame.setBounds(0, 0, 1000, 800); frame.setVisible(true); frame.repaint(); } return plot; }
From source file:ucar.unidata.idv.flythrough.Flythrough.java
/** * _more_/*from ww w . j av a 2s.c o m*/ * * @param g _more_ * @param comp _more_ */ public void paintDashboardAfter(Graphics g, JComponent comp) { Graphics2D g2 = (Graphics2D) g; AffineTransform oldTransform = g2.getTransform(); Rectangle b = dashboardLbl.getBounds(); int w = dashboardImage.getWidth(null); int h = dashboardImage.getHeight(null); Point ul = new Point(b.width / 2 - w / 2, b.height - h); int ptsIdx = 0; try { pipPanel.setPreferredSize(new Dimension(dialPts[ptsIdx][2], dialPts[ptsIdx][3])); pipFrame.setSize(dialPts[ptsIdx][2], dialPts[ptsIdx][3]); pipPanel.doLayout(); pipPanel.validate(); pipFrame.pack(); pipPanel.resetDrawBounds(); pipPanel.redraw(); } catch (Exception ignore) { } JLabel locLbl = null; if (lastLocation != null) { try { locLbl = new JLabel("<html><table width=100%><tr><td align=right> Lat:</td></td>" + getIdv().getDisplayConventions().formatLatLon(getLat(lastLocation)) + "</td></tr>" + "<tr><td align=right> Lon:</td></td>" + getIdv().getDisplayConventions().formatLatLon(getLon(lastLocation)) + "</td></tr>" + "<tr><td align=right> Alt:</td></td>" + getIdv().getDisplayConventions().formatDistance(getAlt(lastLocation)) + "</table>"); } catch (Exception ignore) { } } if (locLbl == null) { locLbl = new JLabel( "<html><table width=100%><tr><td align=right> Lat:</td></td>N/A </td></tr><tr><td align=right> Lon:</td></td>N/A </td></tr><tr><td align=right> Alt:</td></td>N/A </table>"); } locLbl.setOpaque(true); locLbl.setBackground(Color.white); DefaultValueDataset headingDataset = new DefaultValueDataset(new Double(currentHeading)); CompassPlot plot = new CompassPlot(headingDataset); plot.setSeriesNeedle(0); plot.setSeriesPaint(0, Color.red); plot.setSeriesOutlinePaint(0, Color.red); JFreeChart chart = new JFreeChart("", plot); ChartPanel compassPanel = new ChartPanel(chart); plot.setBackgroundPaint(new Color(255, 255, 255, 0)); plot.setBackgroundImageAlpha(0.0f); chart.setBackgroundPaint(new Color(255, 255, 255, 0)); compassPanel.setBackground(new Color(255, 255, 255, 0)); compassPanel.setPreferredSize(dialDimension); // compassPanel.setSize(new Dimension(100,100)); g2.setTransform(oldTransform); pipRect = drawDial(g2, pipPanel, ptsIdx++, ul); JFrame dummyFrame = new JFrame(""); dummyFrame.setContentPane(compassPanel); dummyFrame.pack(); g2.setTransform(oldTransform); drawDial(g2, compassPanel, ptsIdx++, ul); g2.setTransform(oldTransform); dummyFrame.setContentPane(locLbl); dummyFrame.pack(); drawDial(g2, locLbl, ptsIdx++, ul); if (showReadout) { for (JComponent dial : dials) { dummyFrame.setContentPane(dial); dummyFrame.pack(); g2.setTransform(oldTransform); drawDial(g2, dial, ptsIdx++, ul); } } g2.setTransform(oldTransform); }