Java Code Examples for javax.swing.JEditorPane#setSize()

The following examples show how to use javax.swing.JEditorPane#setSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaCoreApi.java    From albert with MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	//load the webpage into the editor
	//JEditorPane ed = new JEditorPane(new URL("http://www.google.com"));
	JEditorPane ed = new JEditorPane(new URL("http://www.baidu.com"));
	System.out.println("10");
	Thread.sleep(10000);
	ed.setSize(1000,1000);

	//create a new image
	BufferedImage image = new BufferedImage(ed.getWidth(), ed.getHeight(),
	                                        BufferedImage.TYPE_INT_ARGB);

	//paint the editor onto the image
	SwingUtilities.paintComponent(image.createGraphics(), 
	                              ed, 
	                              new JPanel(), 
	                              0, 0, image.getWidth(), image.getHeight());
	//save the image to file
	ImageIO.write((RenderedImage)image, "png", new File("html1.png"));
		System.out.println("ok");

}
 
Example 2
Source File: WebStorePanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private double getAdjustedHeight(){
    JEditorPane fakePane = new JEditorPane();
    fakePane.setEditable(false);
    fakePane.setBorder(null);
    fakePane.setContentType("text/html"); // NOI18N
    fakePane.setFont(description.getFont());
    Dimension size = description.getPreferredSize();
    size.setSize( size.getWidth(), Short.MAX_VALUE);
    fakePane.setSize( size);
    fakePane.setText(description.getText());
    Font font = description.getFont();
    String bodyRule = "body { font-family: " + font.getFamily() + "; " +
            "font-size: " + font.getSize() + "pt; }";
    ((HTMLDocument)fakePane.getDocument()).getStyleSheet().addRule(bodyRule);
    return fakePane.getPreferredSize().getHeight();
}
 
Example 3
Source File: AnnotationDrawUtils.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Calculates the preferred height of an editor pane with the given fixed width for the
 * specified string.
 *
 * @param comment
 *            the annotation comment string
 * @param width
 *            the width of the content
 * @return the preferred height given the comment
 */
public static int getContentHeight(final String comment, final int width, final Font font) {
	if (comment == null) {
		throw new IllegalArgumentException("comment must not be null!");
	}
	// do not create Swing components for headless mode
	if (RapidMiner.getExecutionMode().isHeadless()) {
		return 0;
	}
	JEditorPane dummyEditorPane = new JEditorPane("text/html", "");
	dummyEditorPane.setText(comment);
	dummyEditorPane.setBorder(null);
	dummyEditorPane.setSize(width, Short.MAX_VALUE);
	dummyEditorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
	dummyEditorPane.setFont(font);

	// height is not exact. Multiply by magic number to get a more fitting value...
	if (SystemInfoUtilities.getOperatingSystem() == OperatingSystem.OSX
			|| SystemInfoUtilities.getOperatingSystem() == OperatingSystem.UNIX
			|| SystemInfoUtilities.getOperatingSystem() == OperatingSystem.SOLARIS) {
		return (int) (dummyEditorPane.getPreferredSize().getHeight() * 1.05f);
	} else {
		return (int) dummyEditorPane.getPreferredSize().getHeight();
	}
}
 
Example 4
Source File: DefaultHtmlPrintElement.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public JRPrintImage createImageFromElement(JRGenericPrintElement element) {
	String htmlContent = (String) element.getParameterValue(HtmlPrintElement.PARAMETER_HTML_CONTENT);
	String scaleType = (String) element.getParameterValue(HtmlPrintElement.PARAMETER_SCALE_TYPE);
	String horizontalAlignment = (String) element.getParameterValue(HtmlPrintElement.PARAMETER_HORIZONTAL_ALIGN);
	String verticalAlignment = (String) element.getParameterValue(HtmlPrintElement.PARAMETER_VERTICAL_ALIGN);
	
	JEditorPane editorPane = new JEditorPane();
	editorPane.setEditorKitForContentType("text/html", new SynchronousImageLoaderKit());
	editorPane.setContentType("text/html");
	
	editorPane.setText(htmlContent);
	editorPane.setBorder(null);
	editorPane.setSize(editorPane.getPreferredSize());

	JRBasePrintImage printImage = new JRBasePrintImage(element.getDefaultStyleProvider());
	printImage.setX(element.getX());
	printImage.setY(element.getY());
	printImage.setWidth(element.getWidth());
	printImage.setHeight(element.getHeight());
	printImage.setScaleImage(ScaleImageEnum.getByName(scaleType));
	printImage.setHorizontalImageAlign(HorizontalImageAlignEnum.getByName(horizontalAlignment));
	printImage.setVerticalImageAlign(VerticalImageAlignEnum.getByName(verticalAlignment));
	printImage.setStyle(element.getStyle());
	printImage.setMode(element.getModeValue());
	printImage.setBackcolor(element.getBackcolor());
	printImage.setForecolor(element.getForecolor());
	printImage.setRenderer(new AwtComponentRendererImpl(editorPane));

	return printImage;
}
 
Example 5
Source File: DefaultHtmlPrintElement.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public JRPrintImage createImageFromComponentElement(JRComponentElement componentElement) throws JRException {
	HtmlComponent html = (HtmlComponent) componentElement.getComponent();
	
	JEditorPane editorPane = new JEditorPane();
	editorPane.setEditorKitForContentType("text/html", new SynchronousImageLoaderKit());
	editorPane.setContentType("text/html");
	
	String htmlContent = "";
	
	if (html.getHtmlContentExpression() != null) {
		htmlContent = JRExpressionUtil.getExpressionText(html.getHtmlContentExpression());
	}
	
	editorPane.setText(htmlContent);
	editorPane.setBorder(null);
	editorPane.setSize(editorPane.getPreferredSize());
	
	JRBasePrintImage printImage = new JRBasePrintImage(componentElement.getDefaultStyleProvider());
	printImage.setX(componentElement.getX());
	printImage.setY(componentElement.getY());
	printImage.setWidth(componentElement.getWidth());
	printImage.setHeight(componentElement.getHeight());
	printImage.setScaleImage(html.getScaleType());
	printImage.setHorizontalImageAlign(html.getHorizontalImageAlign());
	printImage.setVerticalImageAlign(html.getVerticalImageAlign());
	printImage.setStyle(componentElement.getStyle());
	printImage.setMode(componentElement.getModeValue());
	printImage.setBackcolor(componentElement.getBackcolor());
	printImage.setForecolor(componentElement.getForecolor());

	printImage.setRenderer(new AwtComponentRendererImpl(editorPane));
	
	return printImage;
}
 
Example 6
Source File: Font430.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void addComponentsToPane() {
    editorPane = new JEditorPane("text/html",
            "<html><head><style>body {font-family:'Segoe UI'; font-size:12pt;}</style></head><body>\u4e2d</body></html>");

    if (CALL_GET_FONT_METRICS) {
        editorPane.getFontMetrics(new Font("Segoe UI", Font.PLAIN, 12));
    }

    editorPane.setLocation(0, 0);
    editorPane.setSize(200, 100);

    frame.add(editorPane);

    addWindowListener(this);
}
 
Example 7
Source File: Popup401.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private Popup401() {
    textArea = new JTextArea("§1234567890-=\nqwertyuiop[]\nasdfghjkl;'\\\n`zxcvbnm,./\n");
    editorPane = new JEditorPane("text/html", "§1234567890-=\nqwertyuiop[]\nasdfghjkl;'\\\n`zxcvbnm,./\n");
    editorPane.setSize(300, 300);
    add(editorPane);
}
 
Example 8
Source File: ArtARDemo.java    From COMP3204 with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public JPanel getComponent(int width, int height) throws IOException {
	final JPanel container = new JPanel();
	container.setSize(width, height);
	container.setPreferredSize(container.getSize());

	final OverlayLayout overlay = new OverlayLayout(container);
	container.setLayout(overlay);

	labelField = new JEditorPane();
	labelField.setOpaque(false);
	labelField.setSize(640 - 50, 480 - 50);
	labelField.setPreferredSize(labelField.getSize());
	labelField.setMaximumSize(labelField.getSize());
	labelField.setContentType("text/html");

	// add a HTMLEditorKit to the editor pane
	final HTMLEditorKit kit = new HTMLEditorKit();
	labelField.setEditorKit(kit);

	final StyleSheet styleSheet = kit.getStyleSheet();
	styleSheet.addRule("body {color:#FF00FF; font-family:courier;}");
	styleSheet.addRule("h1 {font-size: 60pt}");
	styleSheet.addRule("h2 {font-size: 50pt }");

	final Document doc = kit.createDefaultDocument();
	labelField.setDocument(doc);

	// final GridBagConstraints gbc = new GridBagConstraints();
	// gbc.gridy = 1;
	// panel.add(labelField, gbc);
	container.add(labelField);
	// labelField.setAlignmentX(0.5f);
	// labelField.setAlignmentY(0.5f);

	final JPanel panel = super.getComponent(width, height);
	container.add(panel);

	vc.getDisplay().addVideoListener(this);

	isRunning = true;
	new Thread(this).start();

	return container;
}