-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
swing1.1
-
x86
-
windows_nt
In my application I need to display a single line of html. I am trying to use JEditorPane for this purpose. The editor always puts a blank
line before my html.
Here is the html:
<HTML>
<TITLE></TITLE>
<BODY>This should be one line
</BODY>
</HTML>
Here is the code:
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.border.*;
import java.net.*;
import java.io.*;
public class Demographics extends JPanel {
public Demographics() {
super();
try {
URL url = this.getClass().getResource("Demographics.html");
JEditorPane html = new JEditorPane(url);
html.setBorder(new LineBorder(Color.black));
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(Box.createVerticalGlue());
add("North", html);
add(Box.createVerticalGlue());
} catch (MalformedURLException e) {
System.out.println("Malformed URL: " + e);
} catch (IOException e) {
System.out.println("IOException: " + e);
}
}
public static void main(String[] args){
JFrame frame = new JFrame("Test Window");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
System.exit(0);
}
});
Demographics demographics = new Demographics();
Container windowContents = frame.getContentPane();
windowContents.setLayout(new BorderLayout());
windowContents.add("Center", demographics);
frame.setSize(400, 300);
frame.show();
}
}
line before my html.
Here is the html:
<HTML>
<TITLE></TITLE>
<BODY>This should be one line
</BODY>
</HTML>
Here is the code:
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.border.*;
import java.net.*;
import java.io.*;
public class Demographics extends JPanel {
public Demographics() {
super();
try {
URL url = this.getClass().getResource("Demographics.html");
JEditorPane html = new JEditorPane(url);
html.setBorder(new LineBorder(Color.black));
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
add(Box.createVerticalGlue());
add("North", html);
add(Box.createVerticalGlue());
} catch (MalformedURLException e) {
System.out.println("Malformed URL: " + e);
} catch (IOException e) {
System.out.println("IOException: " + e);
}
}
public static void main(String[] args){
JFrame frame = new JFrame("Test Window");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
System.exit(0);
}
});
Demographics demographics = new Demographics();
Container windowContents = frame.getContentPane();
windowContents.setLayout(new BorderLayout());
windowContents.add("Center", demographics);
frame.setSize(400, 300);
frame.show();
}
}