Re: JTextField.paintComponent
Aaron Fude wrote:
Hi,
If my overridden paintComponent starts with
public void paintComponent(Graphics g) {
super.paintComponent(g);
should that draw the right background color. I thought yes, but I
discovered no and I have to do?
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
Am I doing the right thing or missing something?
On Windows, a JTextField is opaque by default. If I create one and set
its background color, whether or not I override paintComponent() it
draws the background color unless I leave out the super.paintComponent().
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test extends JFrame {
public test() {
setLayout(new GridBagLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setBackground(Color.RED);
JTextField tf = new JTextField("Hello World"); /* {
public void paintComponent(Graphics g) {
super.paintComponent(g);
}
};
*/
tf.setBackground(Color.BLUE);
add(tf);
pack();
setVisible(true);
}
public static void main(String[] args) {
new test();
}
}
Maybe you could write an SSCCE to demonstrate your problem.
--
Knute Johnson
email s/nospam/knute2009/
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access