Java Code Examples for javax.swing.JComponent.paintImmediately()

The following are Jave code examples for showing how to use paintImmediately() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: marathonv5   File: TransparentFrame.java   View Source Code Vote up 5 votes
protected void paintTransparentFrame() {
    Dimension size = component.getComponent().getSize();
    if (component.getComponent() instanceof JComponent) {
        JComponent jc = (JComponent) component.getComponent();
        jc.paintImmediately(0, 0, size.width, size.height);
    }
    if (disposed) {
        return;
    }
    size = component.getSize();
    Point location = component.getLocation();
    graphics.setColor(BG);
    graphics.fillRect(0 + location.x, 0 + location.y, size.width, size.height);
    String name = component.getRComponentName();
    graphics.setColor(Color.WHITE);
    Font font = new Font(graphics.getFont().getName(), Font.ITALIC | Font.BOLD, 12);
    FontMetrics metrics = graphics.getFontMetrics(font);
    int stringWidth = metrics.stringWidth(name);
    int stringHeight = metrics.getHeight() / 2;
    if (stringWidth < size.width && stringHeight < size.height) {
        graphics.setFont(font);
        graphics.drawString(name, (size.width - stringWidth) / 2 + location.x, (size.height + stringHeight) / 2 + location.y);
    } else if (stringWidth >= size.width || stringHeight >= size.height) {
        graphics.setFont(new Font(graphics.getFont().getName(), Font.ITALIC, 9));
        graphics.drawString(name, 0 + location.x, (size.height + stringHeight) / 2 + location.y);
    } else {
        logger.warning("Not drawing");
    }
}