1 19 20 package org.netbeans.modules.debugger.jpda.ui; 21 22 import java.awt.Font ; 23 import java.util.StringTokenizer ; 24 import javax.swing.Box ; 25 import javax.swing.BoxLayout ; 26 import javax.swing.JLabel ; 27 import javax.swing.JPanel ; 28 29 40 public final class MultilinePanel extends JPanel { 41 42 47 public MultilinePanel(String text) { 48 this(null, text); 49 } 50 51 60 public MultilinePanel(String title, String text) { 61 super(); 62 setLayout(new BoxLayout (this, BoxLayout.Y_AXIS)); 63 if (title != null) { 65 JLabel label = new JLabel (title); 66 label.setFont(label.getFont().deriveFont(Font.BOLD)); 67 add(label); 68 } 69 StringTokenizer tokenizer = new StringTokenizer (text, "\n", true); boolean lastWasNewline = true; 72 for (int i = 0; tokenizer.hasMoreTokens(); ++i) { 73 String line = tokenizer.nextToken(); 74 if ("\n".equals(line)) { if (!lastWasNewline) { 76 lastWasNewline = true; 77 continue; } 79 line = " "; } 82 else { 83 lastWasNewline = false; 84 } 85 add(new JLabel (line)); 86 } 87 add(Box.createVerticalGlue()); 88 } 89 90 } 91 | Popular Tags |