Example usage for javax.swing JTextArea getSize

List of usage examples for javax.swing JTextArea getSize

Introduction

In this page you can find the example usage for javax.swing JTextArea getSize.

Prototype

public Dimension getSize() 

Source Link

Document

Returns the size of this component in the form of a Dimension object.

Usage

From source file:com.sander.verhagen.frame.LineWrapCellRenderer.java

private int getLineCount(JTextArea textArea) {
    AttributedString string = new AttributedString(textArea.getText());
    FontRenderContext fontRenderContext = textArea.getFontMetrics(textArea.getFont()).getFontRenderContext();
    AttributedCharacterIterator characterIterator = string.getIterator();
    LineBreakMeasurer lineBreakMeasurer = new LineBreakMeasurer(characterIterator, fontRenderContext);
    lineBreakMeasurer.setPosition(characterIterator.getBeginIndex());

    int lineCount = 0;
    while (lineBreakMeasurer.getPosition() < characterIterator.getEndIndex()) {
        lineBreakMeasurer.nextLayout(textArea.getSize().width);
        lineCount++;/*from  w w w .ja  v a  2 s .c o  m*/
    }
    return lineCount;
}

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

private JPanel hacerTabla(Pregunta pregunta, List<Opcion> opciones, String perfil) {
    Tabla panel = new Tabla();
    //Panel completo
    //scrollPanel.setBackground(Color.blue);

    //Ttulo pregunta
    JLabel tituloPregunta = new JLabel("\t" + pregunta.getTitulo() + " (" + perfil + ")");
    tituloPregunta.setFont(new Font("Roboto", 1, 24));
    tituloPregunta.setForeground(Color.black);
    tituloPregunta.setVerticalAlignment(JLabel.CENTER);
    JPanel panelHeader = panel.getjPanelHead();
    panelHeader.add(tituloPregunta);/*from  w  ww.j ava 2 s . c om*/
    panelHeader.setOpaque(false);
    panelHeader.setPreferredSize(panelGrafica.getSize());

    //Panel de la tabla
    JPanel tabla = new JPanel(new GridLayout(pregunta.obtenerCantidadDeOpciones() + 2, 3, 5, 5));
    tabla.setBackground(Color.white);

    //Poner el titulo de cada columna
    for (int i = 0; i < 3; i++) {
        JPanel tilt = new JPanel();
        tilt.setBackground(new Color(137, 36, 31));
        JLabel label = new JLabel(i == 0 ? "Opcion" : i == 2 ? "Porcentaje" : "Cantidad");
        label.setFont(new Font("Roboto", 1, 18));
        label.setForeground(Color.white);
        tilt.add(label);
        tilt.setSize(new Dimension(0, 35));
        tilt.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
        tabla.add(tilt);
    }

    int sum = 0;

    for (Opcion opcion : opciones) {
        sum += opcion.getCantidad();
    }

    for (Opcion opc : opciones) {
        JPanel p1 = new JPanel(new GridLayout(0, 1));
        p1.setBackground(Color.white);
        p1.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
        JTextArea l1 = new JTextArea(opc.getNombre());

        l1.setWrapStyleWord(true);
        l1.setLineWrap(true);
        l1.setFont(new Font("Roboto", 0, 18));
        l1.setEditable(false);
        l1.setBorder(null);
        p1.setPreferredSize(l1.getSize());
        p1.add(l1);
        tabla.add(p1);

        JPanel p2 = new JPanel();
        p2.setBackground(Color.white);
        p2.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
        JLabel l2 = new JLabel("" + opc.getCantidad());
        l2.setFont(new Font("Roboto", 0, 18));
        p2.add(l2);
        tabla.add(p2);

        JPanel p3 = new JPanel();
        p3.setBackground(Color.white);
        p3.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
        double porcentaje = (opc.getCantidad() * 100.0) / sum;
        JLabel l3 = new JLabel(String.format("%.2f", porcentaje) + "%");
        l3.setFont(new Font("Roboto", 0, 18));
        p3.add(l3);
        tabla.add(p3);
    }

    JPanel p1 = new JPanel();
    p1.setBackground(Color.white);
    p1.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
    JLabel l1 = new JLabel("Total");
    l1.setHorizontalTextPosition(JLabel.LEFT);
    l1.setFont(new Font("Roboto", 1, 18));
    p1.add(l1);
    tabla.add(p1);

    JPanel p2 = new JPanel();
    p2.setBackground(Color.white);
    p2.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
    JLabel l2 = new JLabel("" + sum);
    l2.setFont(new Font("Roboto", 1, 18));
    p2.add(l2);
    tabla.add(p2);

    JPanel p3 = new JPanel();
    p3.setBackground(Color.white);
    p3.setBorder(new MatteBorder(1, 1, 1, 1, new Color(230, 230, 230)));
    JLabel l3 = new JLabel("100.00%");
    l3.setFont(new Font("Roboto", 1, 18));
    p3.add(l3);
    tabla.add(p3);

    panel.getjPanelContent().add(tabla, BorderLayout.CENTER);

    //Relleno
    JPanel x = new JPanel(new GridLayout());
    x.setPreferredSize(new Dimension(100, 0));
    x.setBackground(Color.white);
    panel.getjPanelContent().add(x, BorderLayout.LINE_START);
    JPanel y = new JPanel(new GridLayout());
    y.setPreferredSize(new Dimension(100, 0));
    y.setBackground(Color.white);
    panel.getjPanelContent().add(y, BorderLayout.LINE_END);
    JPanel z = new JPanel(new GridLayout());
    z.setBackground(Color.white);
    z.setPreferredSize(new Dimension(0, 40));
    panel.getjPanelContent().add(z, BorderLayout.PAGE_END);

    return panel;
}