java - I am trying to set the color of the button,but the color doesn't get set -


how set color of button in swing.

here code. what's problem code.can help?

import java.awt.*; import javax.swing.*; class myb extends jbutton {        public void paint(graphics g)     {         g.setcolor(color.red);      }     public static void main(string s[])     {         jframe f=new jframe("frame");         jbutton b=new jbutton();         b.setbounds(100,100,50,50);         f.add(b);         f.setsize(800,800);         f.setlayout(null);         f.setvisible(true);     } } 

overriding paint not proper way set component's color. can call setbackground method set jbutton's color.

like so:

import java.awt.*; import javax.swing.*; class myb {     public static void main(string[] args)     {         swingutilities.invokelater(new runnable(){public void run(){             jframe f=new jframe("frame");             jbutton b=new jbutton();             b.setbounds(100,100,50,50);             b.setbackground(color.red);             f.add(b);             f.setsize(800,800);             f.setlayout(null);             f.setvisible(true);         }});     } } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -