| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | 22 | package processing.app.ui; | |
| 23 | 23 | ||
| 24 | + import java.awt.Dimension; | ||
| 24 | 25 | import java.awt.EventQueue; | |
| 25 | 26 | import java.io.File; | |
| 26 | 27 | ||
@@ -44,23 +45,35 @@ static public void main(String[] args) { | |||
| 44 | 45 | EventQueue.invokeLater(new Runnable() { | |
| 45 | 46 | public void run() { | |
| 46 | 47 | JFrame frame = new JFrame("Welcome to Processing 3"); | |
| 47 | - frame.setSize(500, 400); | ||
| 48 | - frame.setLocationRelativeTo(null); | ||
| 49 | - | ||
| 50 | - frame.setVisible(true); | ||
| 48 | + // frame.setSize(500, 400); | ||
| 51 | 49 | frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); | |
| 52 | 50 | ||
| 53 | - JTextPane textPane = new JTextPane(); | ||
| 54 | - textPane.setContentType("text/html"); | ||
| 55 | - textPane.setEditable(false); | ||
| 56 | 51 | String[] lines = PApplet.loadStrings(indexFile); | |
| 57 | - textPane.setText(PApplet.join(lines, "\n")); | ||
| 52 | + String content = PApplet.join(lines, "\n"); | ||
| 53 | + | ||
| 54 | + int high = getContentHeight(400, content); | ||
| 55 | + //System.out.println(high); | ||
| 56 | + //JTextPane textPane = new JTextPane(); | ||
| 57 | + //JEditorPane textPane = new JEditorPane(); | ||
| 58 | + JEditorPane textPane = new JEditorPane("text/html", content); | ||
| 59 | + //textPane.setContentType("text/html"); | ||
| 60 | + textPane.setEditable(false); | ||
| 61 | + textPane.setPreferredSize(new Dimension(400, high)); | ||
| 62 | + //String[] lines = PApplet.loadStrings(indexFile); | ||
| 63 | + //textPane.setText(PApplet.join(lines, "\n")); | ||
| 64 | + // System.out.println(textPane.getPreferredSize().height); | ||
| 65 | + // textPane.setSize(400, textPane.getPreferredSize().height); | ||
| 58 | 66 | ||
| 59 | 67 | //frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS)); | |
| 60 | 68 | frame.getContentPane().add(textPane); | |
| 61 | 69 | ||
| 70 | + frame.pack(); | ||
| 71 | + frame.setLocationRelativeTo(null); | ||
| 72 | + frame.setVisible(true); | ||
| 73 | + | ||
| 62 | 74 | HTMLEditorKit kit = (HTMLEditorKit) textPane.getEditorKit(); | |
| 63 | 75 | kit.setAutoFormSubmission(false); | |
| 76 | + | ||
| 64 | 77 | textPane.addHyperlinkListener(new HyperlinkListener() { | |
| 65 | 78 | ||
| 66 | 79 | @Override | |
@@ -87,6 +100,14 @@ public void hyperlinkUpdate(HyperlinkEvent e) { | |||
| 87 | 100 | } | |
| 88 | 101 | }); | |
| 89 | 102 | } | |
| 103 | + | ||
| 104 | + | ||
| 105 | + // Why this doesn't work inline above is beyoned me | ||
| 106 | + static int getContentHeight(int width, String content) { | ||
| 107 | + JEditorPane dummy = new JEditorPane("text/html", content); | ||
| 108 | + dummy.setSize(width, Short.MAX_VALUE); | ||
| 109 | + return dummy.getPreferredSize().height; | ||
| 110 | + } | ||
| 90 | 111 | } | |
| 91 | 112 | ||
| 92 | 113 | /* | |
| Back | FazBrowse Home | New Git URL |
0 commit comments