martes, 25 de febrero de 2014

Source code: MultilineToolTipTest

Código fuente del programa MultilineToolTipTest

Ver la entrada correspondiente en el siguiente enlace:


Tool Tip multilínea en Java Swing

package pruebas;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingUtilities;

public class MultilineToolTipTest {

    public static void test() {
        StringBuilder buf= new StringBuilder();
        buf.append("This is a tool tip:\n");

        for (int i= 0; i < 5; i++) {
            String line= String.format("\t Line %s%n", i);
            buf.append(line);
        }

        String toolTip= buf.toString();
        String toolTipHTML= "<html><body><pre>"+ toolTip + "</pre></body></html>";

        JLabel label1= new JLabel();
        label1.setText("Label with monoline tool tip text.");
        label1.setToolTipText(toolTip);

        JLabel labelN= new JLabel();
        labelN.setText("Label with multiline tool tip text.");
        labelN.setToolTipText(toolTipHTML);

        JPanel content= new JPanel(null);
        BoxLayout boxLayout= new BoxLayout(content, BoxLayout.PAGE_AXIS);
        content.setLayout(boxLayout);
        content.add(label1);
        content.add( new JSeparator(JSeparator.HORIZONTAL) );
        content.add(labelN);

        JFrame frame= new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setContentPane(content);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() { public void run() {
            MultilineToolTipTest.test();
        }});
    }

}

No hay comentarios:

Publicar un comentario