Java Code Examples for javax.swing.SwingUtilities#paintComponent()

The following examples show how to use javax.swing.SwingUtilities#paintComponent() . These examples are extracted from open source projects. 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 Project: albert   File: CobraTest.java    License: MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	JFrame window = new JFrame();
	HtmlPanel panel = new HtmlPanel();
	window.getContentPane().add(panel);
	window.setSize(600, 400);
	window.setVisible(true);
	new SimpleHtmlRendererContext(panel, new SimpleUserAgentContext())
			.navigate("http://jobs.zhaopin.com/377931819252715.htm?ssidkey=y&ss=201&ff=03");
	System.out.println("10");
	Thread.sleep(10000);
	BufferedImage image = new BufferedImage(panel.getWidth(),
			panel.getHeight(), BufferedImage.TYPE_INT_ARGB);

	// paint the editor onto the image
	SwingUtilities.paintComponent(image.createGraphics(), panel,
			new JPanel(), 0, 0, image.getWidth(), image.getHeight());
	// save the image to file
	ImageIO.write((RenderedImage) image, "png", new File("html3.png"));
	System.out.println("www");
}
 
Example 2
Source Project: albert   File: JavaCoreApi.java    License: 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 3
Source Project: netbeans   File: ViewTooltips.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set the cell renderer we will proxy.
 */
public void setComponent (Component jc, JComponent owner) {
    Dimension dd = jc.getPreferredSize();
    Rectangle currentScreenBounds = Utilities.getUsableScreenBounds();
    // get some reasonable limit for the width
    int width = Math.min(dd.width, 2 * currentScreenBounds.width);
    int height = Math.min(dd.height + 2, 2 * currentScreenBounds.height);
    Image nue = !Utilities.isMac() ? owner.createVolatileImage(width, height) :
                new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics g = nue.getGraphics();
    g.setColor (bg);
    g.fillRect (0, 0, width, dd.height + 2);
    if( jc instanceof Container && !jc.isValid() ) {
        //#214739
        jc.setSize( width, dd.height );
        jc.doLayout();
    }
    SwingUtilities.paintComponent(g, jc, this, 0, 0, width, dd.height + 2);
    g.dispose();
    setImage (nue);
}
 
Example 4
public void paintComponent(Graphics g) {
    //Hack for issue 38132 - Beans are set via TTVBridge as a package
    //private property on the parent PropertyPanel (if there is one).
    //FindBeans() will locate the beans either in the model or as a 
    //property of the PropertyPanel (if an esoteric undocumented client property
    //is set on the PropertyPanel).  RendererFactory will set the env
    //value (if there is an env) to the value of ReusablePropertyEnv.NODE
    //(a performance hack to avoid creating 1 property env for each property
    //painted each time we paint).  Cool, huh?
    reusableEnv.setNode(EditorPropertyDisplayer.findBeans(this));

    JComponent comp = getRenderer(this);
    prepareRenderer(comp);
    comp.setBounds(0, 0, getWidth(), getHeight());

    if (comp instanceof InplaceEditor) {
        Component inner = findInnermostRenderer(comp);
        SwingUtilities.paintComponent(g, comp, this, 0, 0, getWidth(), getHeight());
        removeAll();
        return;
    }

    comp.paint(g);
}
 
Example 5
public void paintBorder(Component c, Graphics g, int x, int y, int width,
        int height) {
    Insets borderInsets = border.getBorderInsets(c);
    Insets insets = getBorderInsets(c);
    int temp = (insets.top - borderInsets.top) / 2;
    border.paintBorder(c, g, x, y + temp, width, height - temp);
    Dimension size = comp.getPreferredSize();
    rect = new Rectangle(offset, 0, size.width, size.height);
    SwingUtilities.paintComponent(g, comp, (Container) c, rect);
}
 
Example 6
Source Project: Spark   File: ComponentTitledBorder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
       Insets borderInsets = border.getBorderInsets(c);
       Insets insets = getBorderInsets(c);
       int temp = (insets.top - borderInsets.top) / 2;
       border.paintBorder(c, g, x, y + temp, width, height - temp);
       Dimension size = comp.getPreferredSize();
       rect = new Rectangle(offset, 0, size.width, size.height);
       SwingUtilities.paintComponent(g, comp, (Container)c, rect);
   }
 
Example 7
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    SwingUtilities.paintComponent(
            g, check, (Container) c, x, y, getIconWidth(), getIconHeight());
}