Home arrow static arrow Java Programming [Archive] - about LookAndFeel
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - about LookAndFeel
This topic has 1 reply on 1 page.

Posts:260
Registered: 4/8/04
about LookAndFeel  
Jun 26, 2004 4:42 AM



 
why all Buttons cant change default color

//<applet code=SendTest width=400 height=350></applet>
import javax.swing.*;
import java.awt.*;
public class SendTest extends JApplet{
JButton connectbutton=new JButton("connect");
JButton clear=new JButton("Text Clear");
JButton send=new JButton("send SQL");

JLabel IPlabel=new JLabel("IP addr");
JLabel Portlabel=new JLabel("port");
JLabel SQLlabel=new JLabel("SQL");
JTextField IPtext=new JTextField(8);
JTextField Porttext=new JTextField(3);
JTextField SQLtext=new JTextField(25);
JRadioButton rb3=new JRadioButton("Operate All Data",true);
JRadioButton rb4=new JRadioButton("Operate Result",false);
ButtonGroup group1=new ButtonGroup();

JTextArea receive=new JTextArea(10,25);

JLabel storelabel=new JLabel("DataBase");
JLabel namelabel=new JLabel("username");
JLabel passwdlabel=new JLabel("passwd");
JTextField storetext=new JTextField(10);
JTextField nametxt=new JTextField(10);
JPasswordField passwdtxt=new JPasswordField(10);
JRadioButton rb1=new JRadioButton("save Result",true);
JRadioButton rb2=new JRadioButton("drop Result",false);
ButtonGroup group=new ButtonGroup();
public void init(){
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e){}
Container cp=getContentPane();

JScrollPane scroll=new JScrollPane(receive);
JPanel all=new JPanel();
all.setLayout(new BoxLayout(all,BoxLayout.Y_AXIS));
JPanel top=new JPanel();
top.setLayout(new FlowLayout());
top.add(IPlabel);
top.add(IPtext);
top.add(Portlabel);
top.add(Porttext);
top.add(connectbutton);

JPanel text=new JPanel();
text.setLayout(new FlowLayout());
text.add(SQLlabel);
text.add(SQLtext);

JPanel buttons=new JPanel();
buttons.setLayout(new FlowLayout());
buttons.add(send);
buttons.add(clear);

JPanel radios=new JPanel();
radios.setLayout(new FlowLayout());
group1.add(rb3);
group1.add(rb4);
radios.add(rb3);
radios.add(rb4);

all.add(top);
all.add(text);
all.add(radios);
all.add(buttons);
all.add(scroll);
cp.add(all);
}
}

 

Posts:2,275
Registered: 10/18/03
Re: about LookAndFeel  
Jun 26, 2004 6:15 AM (reply 1 of 1)



 
An applet or 'JApplet' is built upon;-

(java.lang.Object)
- java.awt.Component (abstract class)
- - - java.awt.Container (concrete)
- - - - - java.awt.Panel
- - - - - - - java.applet.Applet
- - - - - - - - - javax.swing.JApplet

So it has all of the above classes and their methods available to it. This includes;-
setBackgound() and setForeground() methods [from java.awt.Component]
- these will effect the Panel (or in the case of a JApplet, the JPanel which needs to explicitly instantiated as it is not part of the inheritance tree above)
- There is no Button in this inheritance structure which looks like;-
java.lang.Object
- java.awt.Component
- - - java.awt.Container
- - - - - javax.swing.JComponent (all abstract)
- - - - - - - javax.swing.AbstractButton (generic button class)
- - - - - - - - - javax.swing.JButton (the only concrete class in the tree)

So setting the colour for the JApplet Container cannot effect the JButton

you have to set the foreground and background wiki/./colour for each button

PS I'd use a custom ;-
"JButton createButton(Color backColour, Color foreColour, String buttonLabel, Font){...return"
- method, which would make things much easier if you wanted to do a lot of customisation to a lot of Buttons in your app
 
This topic has 1 reply on 1 page.