Example usage for javax.swing JPanel getBounds

List of usage examples for javax.swing JPanel getBounds

Introduction

In this page you can find the example usage for javax.swing JPanel getBounds.

Prototype

public Rectangle getBounds() 

Source Link

Document

Gets the bounds of this component in the form of a Rectangle object.

Usage

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.pack();/*from  www .  j a  va2 s . c om*/

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(null);
    for (int i = 0; i < 4; i++) {
        JPanel panel = new JPanel();
        panel.setBounds((i * 75) + 475, 25, 75, 100);
        System.out.println(panel.getBounds());
        contentPane.add(panel);
        panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 3));
    }
    System.out.println(getComponentAt(contentPane, new Point(475, 25)));
    System.out.println(getComponentAt(contentPane, new Point(100, 25)));
    frame.setVisible(true);
}

From source file:org.jfreechart.SVGExporter.java

public static Action createExportAction(final JFreeChart chart, final JPanel bounds) {
    return new AbstractAction("Save as SVG...") {

        public void actionPerformed(ActionEvent e) {
            try {
                JFileChooser fc = new JFileChooser();
                fc.showSaveDialog(null);
                if (fc.getSelectedFile() != null) {
                    exportChartAsSVG(chart, bounds.getBounds(), fc.getSelectedFile());
                }//from  w  w w . java2 s. c  om
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    };
}

From source file:org.gumtree.vis.awt.CompositePanel.java

@Override
public BufferedImage getImage() {
    BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D gc2 = image.createGraphics();
    gc2.setBackground(Color.white);
    gc2.setPaint(Color.white);/*  ww w. ja v  a 2s.c o m*/
    gc2.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
    for (IPlot plot : plotList) {
        if (plot instanceof JPanel) {
            JPanel panel = (JPanel) plot;
            Rectangle2D panelBounds = panel.getBounds();
            Image panelImage = plot.getImage();
            gc2.drawImage(panelImage, (int) panelBounds.getMinX(), (int) panelBounds.getMinY(), panel);
        }
    }
    gc2.dispose();
    return image;
}

From source file:com.polivoto.vistas.Charts.java

private JPanel hacerPiePanel(Pregunta pregunta, List<Opcion> opciones) {
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBackground(Color.white);
    DefaultPieDataset data = new DefaultPieDataset();
    // Fuente de Datos
    for (Opcion opc : opciones) {
        data.setValue(opc.getNombre(), opc.getCantidad());
    }//from w w w  .j  a va  2s .  co m

    // Creando el Grafico
    JFreeChart chart = ChartFactory.createPieChart("\n" + pregunta.getTitulo(), data, true, false, //TOOLTIPS
            false);
    chart.setBackgroundPaint(Color.white);
    chart.getTitle().setFont(new Font("Roboto", 0, 28));

    // Crear el Panel del Grafico con ChartPanel
    ChartPanel chartPanel = new ChartPanel(chart);
    PiePlot plot = (PiePlot) chart.getPlot();

    Rectangle bounds = panel.getBounds();
    chartPanel.setBounds(bounds.x, bounds.y, bounds.height, bounds.height);

    panel.add(chartPanel);

    plot.setLabelGenerator(null);
    plot.setBackgroundPaint(Color.white);
    plot.setOutlineVisible(false);
    //StandardPieSectionLabelGenerator labels = new StandardPieSectionLabelGenerator("{0} = {1}");
    //plot.setLabelGenerator(labels);

    plot.setBaseSectionOutlinePaint(Color.white);
    plot.setShadowXOffset(0);
    plot.setShadowYOffset(0);

    //#7cb5ec,#f45b5b,#90ed7d,#434348,
    //#f7a35c,#8085e9,#f15c80,#e4d354,
    //#2b908f,#91e8e1
    Color[] colors = { new Color(124, 181, 236), new Color(244, 91, 91), new Color(144, 237, 125),
            new Color(67, 67, 72), new Color(247, 163, 92), new Color(128, 133, 233), new Color(241, 92, 128),
            new Color(228, 211, 84), new Color(43, 144, 143), new Color(145, 232, 225) };
    PieRenderer renderer = new PieRenderer(colors);
    renderer.setColor(plot, data);

    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.RIGHT);
    Font nwfont = new Font("Roboto", 0, 18);
    legend.setItemFont(nwfont);
    legend.setFrame(new BlockBorder(0, 0, 0, 90, Color.white));
    legend.setBackgroundPaint(Color.WHITE);
    legend.setItemLabelPadding(new RectangleInsets(8, 8, 8, 0));
    //RectangleInsets padding = new RectangleInsets(5, 5, 5, 5);
    //legend.setItemLabelPadding(padding);
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{1} {0}"));
    plot.setLegendItemShape(new Rectangle(25, 25));
    return panel;
}