Skip to content

Commit 6ae18cb

Browse files
committed
automatically detect height
1 parent 2c97736 commit 6ae18cb

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

app/src/processing/app/ui/Welcome.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
package processing.app.ui;
2323

24+
import java.awt.Dimension;
2425
import java.awt.EventQueue;
2526
import java.io.File;
2627

@@ -44,23 +45,35 @@ static public void main(String[] args) {
4445
EventQueue.invokeLater(new Runnable() {
4546
public void run() {
4647
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);
5149
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
5250

53-
JTextPane textPane = new JTextPane();
54-
textPane.setContentType("text/html");
55-
textPane.setEditable(false);
5651
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);
5866

5967
//frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
6068
frame.getContentPane().add(textPane);
6169

70+
frame.pack();
71+
frame.setLocationRelativeTo(null);
72+
frame.setVisible(true);
73+
6274
HTMLEditorKit kit = (HTMLEditorKit) textPane.getEditorKit();
6375
kit.setAutoFormSubmission(false);
76+
6477
textPane.addHyperlinkListener(new HyperlinkListener() {
6578

6679
@Override
@@ -87,6 +100,14 @@ public void hyperlinkUpdate(HyperlinkEvent e) {
87100
}
88101
});
89102
}
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+
}
90111
}
91112

92113
/*

0 commit comments

Comments
 (0)