Example usage for java.awt Graphics getClipBounds

List of usage examples for java.awt Graphics getClipBounds

Introduction

In this page you can find the example usage for java.awt Graphics getClipBounds.

Prototype

public abstract Rectangle getClipBounds();

Source Link

Document

Returns the bounding rectangle of the current clipping area.

Usage

From source file:Java2DUtils.java

@SuppressWarnings("unchecked")
public static void setClip(Graphics g, Rectangle clipBounds) {
    Rectangle currentClipBounds;//from w  ww  .j  av a2s.  co  m

    clipBounds = new Rectangle(clipBounds);
    clipBounds.width += 1;
    clipBounds.height += 1;

    currentClipBounds = g.getClipBounds();
    if (currentClipBounds != null) {
        clipBounds = clipBounds.intersection(g.getClipBounds());
    }

    clipBoundsStack.push(currentClipBounds);
    g.setClip(clipBounds);
}

From source file:Main.java

public void paint(Graphics g) {
    g.drawString(g.getClipBounds() + "", 10, 30);
}

From source file:Main.java

@Override
protected void paintComponent(Graphics g) {
    Rectangle clip = g.getClipBounds();
    g.setColor(new Color(new Random().nextInt()));
    g.fillRect(clip.x, clip.y, clip.width, clip.height);
}

From source file:MainClass.java

public void paint(Graphics g) {
    g.drawString(g.getClipBounds().toString(), 10, 30);

    g.clipRect(10, 40, getSize().width - 20, getSize().height - 80);

    g.fillOval(0, 0, getSize().width, getSize().height);

    String newClip = g.getClipBounds().toString();

    g.setClip(0, 0, getSize().width, getSize().height);

    g.drawString(newClip, 10, getSize().height - 10);
}

From source file:Main.java

public void paint(Graphics g) {
    g.drawString(g.getClipBounds().toString(), 10, 30);

    g.clipRect(10, 40, getSize().width - 20, getSize().height - 80);

    g.fillOval(0, 0, getSize().width, getSize().height);

    String newClip = g.getClipBounds().toString();

    g.setClip(0, 0, getSize().width, getSize().height);

    g.drawString(newClip, 10, getSize().height - 10);

}

From source file:Main.java

public void paint(Graphics g) {
    super.paint(g);
    Rectangle r = g.getClipBounds();
    g.drawLine(0, 0, r.width, r.height);

}

From source file:UnderlinedLabel.java

public void paint(Graphics g) {
    Rectangle r;//from w  w w  . ja  va 2s .  c o  m
    super.paint(g);
    r = g.getClipBounds();
    g.drawLine(0, r.height - getFontMetrics(getFont()).getDescent(),
            getFontMetrics(getFont()).stringWidth(getText()),
            r.height - getFontMetrics(getFont()).getDescent());
}

From source file:Main.java

public Main() {
    super("JScrollPane Demo");
    JScrollPane scrollPane = new JScrollPane(label);

    JLabel[] corners = new JLabel[4];
    for (int i = 0; i < 4; i++) {
        corners[i] = new JLabel();
        corners[i].setBackground(Color.white);
        corners[i].setOpaque(true);//from w  w w  .j  a v a 2s .com
    }

    JLabel rowheader = new JLabel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Rectangle rect = g.getClipBounds();
            for (int i = 50 - (rect.y % 50); i < rect.height; i += 50) {
                g.drawLine(0, rect.y + i, 3, rect.y + i);
                g.drawString("" + (rect.y + i), 6, rect.y + i + 3);
            }
        }

        public Dimension getPreferredSize() {
            return new Dimension(25, (int) label.getPreferredSize().getHeight());
        }
    };
    rowheader.setBackground(Color.white);
    rowheader.setOpaque(true);

    JLabel columnheader = new JLabel() {

        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Rectangle r = g.getClipBounds();
            for (int i = 50 - (r.x % 50); i < r.width; i += 50) {
                g.drawLine(r.x + i, 0, r.x + i, 3);
                g.drawString("" + (r.x + i), r.x + i - 10, 16);
            }
        }

        public Dimension getPreferredSize() {
            return new Dimension((int) label.getPreferredSize().getWidth(), 25);
        }
    };
    columnheader.setBackground(Color.white);
    columnheader.setOpaque(true);

    scrollPane.setRowHeaderView(rowheader);
    scrollPane.setColumnHeaderView(columnheader);
    scrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, corners[0]);
    scrollPane.setCorner(JScrollPane.LOWER_RIGHT_CORNER, corners[1]);
    scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, corners[2]);
    scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, corners[3]);

    getContentPane().add(scrollPane);
    setSize(400, 300);
    setVisible(true);
}

From source file:HeaderDemo.java

public HeaderDemo() {
    super("JScrollPane Demo");
    JScrollPane scrollPane = new JScrollPane(label);

    JLabel[] corners = new JLabel[4];
    for (int i = 0; i < 4; i++) {
        corners[i] = new JLabel();
        corners[i].setBackground(Color.white);
        corners[i].setOpaque(true);/*from ww w .j  av a 2s  . c o m*/
    }

    JLabel rowheader = new JLabel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Rectangle rect = g.getClipBounds();
            for (int i = 50 - (rect.y % 50); i < rect.height; i += 50) {
                g.drawLine(0, rect.y + i, 3, rect.y + i);
                g.drawString("" + (rect.y + i), 6, rect.y + i + 3);
            }
        }

        public Dimension getPreferredSize() {
            return new Dimension(25, (int) label.getPreferredSize().getHeight());
        }
    };
    rowheader.setBackground(Color.white);
    rowheader.setOpaque(true);

    JLabel columnheader = new JLabel() {

        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Rectangle r = g.getClipBounds();
            for (int i = 50 - (r.x % 50); i < r.width; i += 50) {
                g.drawLine(r.x + i, 0, r.x + i, 3);
                g.drawString("" + (r.x + i), r.x + i - 10, 16);
            }
        }

        public Dimension getPreferredSize() {
            return new Dimension((int) label.getPreferredSize().getWidth(), 25);
        }
    };
    columnheader.setBackground(Color.white);
    columnheader.setOpaque(true);

    scrollPane.setRowHeaderView(rowheader);
    scrollPane.setColumnHeaderView(columnheader);
    scrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, corners[0]);
    scrollPane.setCorner(JScrollPane.LOWER_RIGHT_CORNER, corners[1]);
    scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, corners[2]);
    scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, corners[3]);

    getContentPane().add(scrollPane);
    setSize(400, 300);
    setVisible(true);
}

From source file:URLLabel.java

public void paint(Graphics g) {
    super.paint(g);

    if (entered || !mousehover) {
        Rectangle r = g.getClipBounds();

        g.drawLine(0, r.height - this.getFontMetrics(this.getFont()).getDescent(),
                this.getFontMetrics(this.getFont()).stringWidth(this.getText()),
                r.height - this.getFontMetrics(this.getFont()).getDescent());
    }/*from w  w  w. j  av a2  s . c  o m*/
}