Skip to main content

drawstring in xor mode

1 reply [Last post]
brian101
Offline
Joined: 2010-03-22
Points: 0

is there a way to use java.awt.graphics.drawstring in xor mode? I need to put some textual information onto a drawing and then remove it similar to what I am doing for various lines and shapes.

thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jlover2010
Offline
Joined: 2010-01-15
Points: 0

> is there a way to use java.awt.graphics.drawstring in
> xor mode?

Yes!

> I need to put some textual information onto
> a drawing [b]and then remove it similar to what I am
> doing for various lines and shapes. [/b]

I didn't get what you mean (specially the phrase in bold)
But i created demo:

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class XORModePaintDemo {

public static void main(String[] args) {
final JFrame frame = new JFrame();
JPanel panel = new JPanel(){
@Override
public void paintComponent(java.awt.Graphics g){
int width = frame.getWidth();
int height = frame.getHeight();
g.setColor(Color.black);
g.fillRect(0, 0, width/2, height);
g.setColor(Color.white);
g.fillRect(width/2, 0, width/2, height);
g.setXORMode(Color.black); // you can set whatever color !
g.drawString("this is a drawing of some string in XOR mode", width/4, height/2);
}
};
frame.getContentPane().add(panel);
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(3);
}

}

Hope that help...