List of usage examples for javax.swing JPanel getSize
public Dimension getSize()
From source file:org.jw.service.factory.StatisticsChartFactory.java
public static void connectChartPanel(JPanel container, JFreeChart chart) { ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setSize(container.getSize()); container.add(chartPanel);/*from w ww. j a v a 2 s .com*/ }
From source file:logica_controladores.controlador_estadistica.java
public static void grafica_reorden(JPanel panel_grafica_orden, Inventario inventario, JLabel lbLinea) { XYSeries serie_2 = null;//from ww w .java2 s . c om XYDataset datos; JFreeChart linea; serie_2 = new XYSeries("graficas relacion gastos-reorden"); for (int i = 0; i < inventario.getGastos().size(); i++) { serie_2.add(inventario.getGastos().get(i).getReorden(), inventario.getGastos().get(i).getGastos()); } datos = new XYSeriesCollection(serie_2); linea = ChartFactory.createXYLineChart("grafica representativa de reordenes por corrida", "punto de orden", "gastos", datos, PlotOrientation.VERTICAL, true, true, true); BufferedImage graficoLinea = linea.createBufferedImage(panel_grafica_orden.getWidth(), panel_grafica_orden.getHeight()); lbLinea.setSize(panel_grafica_orden.getSize()); lbLinea.setIcon(new ImageIcon(graficoLinea)); panel_grafica_orden.updateUI(); }
From source file:gui.images.CodebookVectorProfilePanel.java
/** * Generate a BufferedImage that would correspond to a JPanel. Images are * faster to show than interactive components if many components need to be * presented./*w ww . j ava 2s .c o m*/ * * @param panel JPanel object. * @return BufferedImage of how the content in the provided panel would be * rendered. */ public BufferedImage createImage(JPanel panel) { int width = panel.getSize().width; int height = panel.getSize().height; BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); panel.paint(g); return bi; }
From source file:logica_controladores.controlador_estadistica.java
public static void grafica_orden(JPanel panel_grafica_orden, Inventario inventario, JLabel lbLinea) { XYSeries serie = null;/*from w w w .j av a 2s . com*/ XYSeries serie_2 = null; JFreeChart linea; serie = new XYSeries("graficas relacion gastos-orden"); Gasto gasto_minimo = valor_minimo(inventario); Gasto gasto_max = valor_maximo(inventario); for (int i = 0; i < inventario.getGastos().size(); i = i + inventario.getReorden_max()) { serie.add(inventario.getGastos().get(i).getOrden_inicial(), inventario.getGastos().get(i).getGastos()); } serie_2 = new XYSeries("graficas relacion gastos-reorden"); for (int i = 0; i < inventario.getGastos().size(); i = i + inventario.getOrden_max()) { serie_2.add(inventario.getGastos().get(i).getReorden(), inventario.getGastos().get(i).getGastos()); } final XYSeriesCollection datos = new XYSeriesCollection(); datos.addSeries(serie); datos.addSeries(serie_2); linea = ChartFactory.createXYLineChart( "grafica representativa de ordenes por corrida, gasto_minimo(orden: " + gasto_minimo.getOrden_inicial() + "reorden: " + gasto_minimo.getReorden() + ")= " + gasto_minimo.getGastos(), "rango", "gastos", datos, PlotOrientation.VERTICAL, true, true, true); final XYPlot plot = (XYPlot) linea.getPlot(); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); configurarDomainAxis(domainAxis, inventario); configurarRangeAxis(rangeAxis, gasto_minimo.getGastos(), gasto_max.getGastos()); BufferedImage graficoLinea = linea.createBufferedImage(600, 280); lbLinea.setSize(panel_grafica_orden.getSize()); lbLinea.setIcon(new ImageIcon(graficoLinea)); panel_grafica_orden.updateUI(); }
From source file:es.emergya.ui.plugins.AdminPanel.java
public AdminPanel(String t, Icon icon, Option myself, boolean canCreateNew, boolean canDelete) { super();/* w w w . j a v a2 s . c o m*/ setCanCreateNew(canCreateNew); setCanDelete(canDelete); setLayout(new SpringLayout()); this.father = myself; setBackground(Color.WHITE); // Titulo con icono JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); title = new JLabel(t); title.setIcon(icon); title.setFont(LogicConstants.deriveBoldFont(12f)); title.setBorder(new EmptyBorder(0, 10, 0, 10)); titlePanel.add(title); titlePanel.setOpaque(false); add(titlePanel); Dimension d = titlePanel.getSize(); if (icon != null) d.height = icon.getIconHeight(); titlePanel.setMaximumSize(d); // Controles de "nuevo" "seleccionar todos" etc... JPanel controls = new JPanel(new FlowLayout(FlowLayout.LEADING)); controls.setOpaque(false); final boolean femenino = t.indexOf("atrulla") != -1 || t.indexOf("apa") != -1 || t.indexOf("lota") != -1 || t.indexOf("encia") != -1; if (getCanCreateNew()) { if (femenino) { newButton = new JButton("Nueva", getIcon("button_nuevo")); } else { newButton = new JButton("Nuevo", getIcon("button_nuevo")); } controls.add(newButton); } if (getCanDelete()) { JButton selectAll = new JButton(((femenino) ? "Seleccionar Todas" : "Seleccionar Todos"), getIcon("button_selectall")); selectAll.addActionListener(this); controls.add(selectAll); deselectAll = new JButton(((femenino) ? "Deseleccionar Todas" : "Deseleccionar Todos"), getIcon("button_unselectall")); deselectAll.addActionListener(this); controls.add(deselectAll); JButton deleteAll = new JButton(((femenino) ? "Eliminar Seleccionadas" : "Eliminar Seleccionados"), getIcon("button_delall")); deleteAll.addActionListener(this); controls.add(deleteAll); } d = controls.getSize(); controls.setMaximumSize(d); add(controls); // Tabla tablePanel = new JPanel(new BorderLayout()); tablePanel.setOpaque(false); add(tablePanel); SpringUtilities.makeCompactGrid(this, 3, 1, 0, 0, 0, 0); }
From source file:velocitekProStartAnalyzer.MainWindow.java
private void saveMapAsPng(JPanel panel) { btnSaveMapAsPng.addActionListener(new ActionListener() { @Override/*from w w w . j a v a2 s .co m*/ public void actionPerformed(ActionEvent e) { fileChooser.setDialogTitle("Specify a file to save"); int userSelection = fileChooser.showSaveDialog(frame); BufferedImage bufImage = new BufferedImage(panel.getSize().width, panel.getSize().height, BufferedImage.TYPE_INT_RGB); panel.paint(bufImage.createGraphics()); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = new File(fileChooser.getSelectedFile() + ".png"); System.out.println("Save as file: " + fileToSave.getAbsolutePath()); try { fileToSave.createNewFile(); ImageIO.write(bufImage, "png", fileToSave); statusLabel.setText("Map Screenshot Saved as: " + fileToSave.getName()); } catch (Exception ex) { statusLabel.setText("There was an error during save, aborted"); } } } }); btnSaveMapAsPngForChart.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { fileChooser.setDialogTitle("Specify a file to save"); int userSelection = fileChooser.showSaveDialog(frame); BufferedImage bufImage = new BufferedImage(panel.getSize().width, panel.getSize().height, BufferedImage.TYPE_INT_RGB); panel.paint(bufImage.createGraphics()); if (userSelection == JFileChooser.APPROVE_OPTION) { File fileToSave = new File(fileChooser.getSelectedFile() + ".png"); System.out.println("Save as file: " + fileToSave.getAbsolutePath()); try { fileToSave.createNewFile(); ImageIO.write(bufImage, "png", fileToSave); statusLabel.setText("Map Screenshot Saved as: " + fileToSave.getName()); } catch (Exception ex) { statusLabel.setText("There was an error during save, aborted"); } } } }); // File imageFile = new File("C:\\MJ_NETCLINIC\\asd.png"); }
From source file:fxts.stations.util.preferences.EditAction.java
public void actionPerformed(ActionEvent aEvent) { JButton okButton = UIManager.getInst().createButton(); JButton cancelButton = UIManager.getInst().createButton(); final JDialog dialog = new JDialog(mEditorPanel.getParentDialog()); dialog.setTitle(mEditorPanel.getTitle()); JPanel editPanel = new JPanel(); JPanel buttonPanel = new JPanel(); JPanel mainPanel = new JPanel(); mainPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); //mainPanel.setLayout(new SideLayout()); //sets button panel buttonPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); okButton.setText(mResMan.getString("IDS_OK_BUTTON")); //okButton.setPreferredSize(new Dimension(80, 27)); GridBagConstraints sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 0;//w w w. j av a2 s . co m sideConstraints.gridy = 0; ResizeParameterWrapper resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.5, 0.0, 0.5, 0.0); resizeParameter.setToConstraints(sideConstraints); buttonPanel.add(okButton, sideConstraints); cancelButton.setText(mResMan.getString("IDS_CANCEL_BUTTON")); //cancelButton.setPreferredSize(new Dimension(80, 27)); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 1; sideConstraints.gridy = 0; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.5, 0.0, 0.5, 0.0); resizeParameter.setToConstraints(sideConstraints); buttonPanel.add(cancelButton, sideConstraints); //adds button panel sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.insets = new Insets(10, 10, 10, 10); sideConstraints.gridx = 0; sideConstraints.gridy = 1; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 1.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); mainPanel.add(buttonPanel, sideConstraints); //sets edit panel final IEditor editor = mType.getEditor(); editor.setValue(mValue); editPanel.setLayout(UIFrontEnd.getInstance().getSideLayout()); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); Component editComp = editor.getComponent(); //Mar 25 2004 - kav: added for right tab order at Font Chooser at java 1.4. if (editComp instanceof FontChooser) { FontChooser fc = (FontChooser) editComp; fc.setNextFocusedComp(okButton); } editPanel.add(editComp, sideConstraints); //adds editor panel sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.gridx = 0; sideConstraints.gridy = 0; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); mainPanel.add(editPanel, sideConstraints); //adds main panel dialog.getContentPane().setLayout(UIFrontEnd.getInstance().getSideLayout()); //dialog.getContentPane().setLayout(new SideLayout()); sideConstraints = UIFrontEnd.getInstance().getSideConstraints(); sideConstraints.fill = GridBagConstraints.BOTH; resizeParameter = UIFrontEnd.getInstance().getResizeParameter(); resizeParameter.init(0.0, 0.0, 1.0, 1.0); resizeParameter.setToConstraints(sideConstraints); dialog.getContentPane().add(mainPanel, sideConstraints); //adds listeners to buttons okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { if (editor.getValue().equals(mValue)) { // } else { mValue = editor.getValue(); mEditorPanel.setValue(mValue); mEditorPanel.refreshControls(); mEditorPanel.setValueChanged(true); } dialog.setVisible(false); dialog.dispose(); } }); okButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "ExitAction"); okButton.getActionMap().put("ExitAction", new AbstractAction() { /** * Invoked when an action occurs. */ public void actionPerformed(ActionEvent aEvent) { editor.setValue(mValue); dialog.setVisible(false); dialog.dispose(); } }); okButton.requestFocus(); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent aEvent) { editor.setValue(mValue); dialog.setVisible(false); dialog.dispose(); } }); //dialog.setResizable(false); dialog.setModal(true); dialog.pack(); //sets minimal sizes for components Dimension dim = mainPanel.getSize(); mainPanel.setMinimumSize(dim); mainPanel.setPreferredSize(dim); //sets size of buttons Dimension dimOkButton = okButton.getSize(); Dimension dimCancelButton = cancelButton.getSize(); int nMaxWidth = dimOkButton.getWidth() > dimCancelButton.getWidth() ? (int) dimOkButton.getWidth() : (int) dimCancelButton.getWidth(); okButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight())); okButton.setSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight())); cancelButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight())); cancelButton.setSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight())); dialog.setLocationRelativeTo(dialog.getOwner()); dialog.setVisible(true); }
From source file:org.monkeys.gui.PopupWindow.java
public void setPanel(final JPanel panel) { this.panel = panel; this.getContentPane().removeAll(); if (null == panel) { return;// w w w . j a v a 2 s .co m } Dimension size = panel.getPreferredSize(); if (null == size) { size = panel.getSize(); } if (size != null) { this.setSize(size); this.setPreferredSize(size); } final GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; this.setLayout(new GridBagLayout()); this.getContentPane().add(panel, c); }