Fórum Aparências de interface - Look and Feel #566038
09/04/2009
0
for (int i = 0; i < looks.length; i++){
escolha[i] = new JRadioButton( looks[i].getName() );
public void atualiza(int i){
try {
UIManager.setLookAndFeel(looks[i].getClassName());
SwingUtilities.updateComponentTreeUI(this);
}catch(Exception e) {
e.printStackTrace();
}
}
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class LFDemo extends JFrame{
private UIManager.LookAndFeelInfo[] looks =
UIManager.getInstalledLookAndFeels();
private JLabel lbLabel01 = new JLabel("Nome :");
private JLabel lbLabel02 = new JLabel("E-mail :");
private JTextField jtTexto01 = new JTextField( 10 );
private JTextField jtTexto02 = new JTextField( 10 );
private JButton jbOk = new JButton("Enviar");
private JButton jbLim = new JButton("Limpar");
private JRadioButton[] escolha = new JRadioButton[ looks.length ];
private ButtonGroup grupo = new ButtonGroup();
public static void main( String[] args ){
LFDemo lfd = new LFDemo();
lfd.show();
}
public LFDemo(){
super("Selecione um LF");
Container c = getContentPane();
c.setLayout ( new FlowLayout());
c.add(lbLabel01);
c.add(jtTexto01);
c.add(lbLabel02);
c.add(jtTexto02);
c.add(jbOk);
c.add(jbLim);
ItemSelecionado iselect = new ItemSelecionado();
for (int i = 0; i < looks.length; i++){
escolha[i] = new JRadioButton( looks[i].getName() );
escolha[i].addItemListener( iselect );
grupo.add( escolha[i] );
c.add( escolha[i] );
}
escolha[2].setSelected( true );
setDefaultCloseOperation( EXIT_ON_CLOSE );
setSize(200,250);
}
public void atualiza(int i){
try {
UIManager.setLookAndFeel(looks[i].getClassName());
SwingUtilities.updateComponentTreeUI(this);
}catch(Exception e) {
e.printStackTrace();
}
}
private class ItemSelecionado implements ItemListener {
public void itemStateChanged( ItemEvent e) {
for (int i=0; i < escolha.length; i++){
if (escolha[i].isSelected())
atualiza(i);
}
}
}
}
Vitor Pamplona
Curtir tópico
+ 0Posts
09/04/2009
Ricardo
Gostei + 0
09/04/2009
Nélio Mesquita
Gostei + 0
09/04/2009
Jairo Luiz
Gostei + 0
09/04/2009
Leonardo Moreira
Gostei + 0
09/04/2009
Pcmnac
Gostei + 0
09/04/2009
Jonatas Moraes
public class LookAndFeel extends JPanel implements ActionListener {
private JButton metalButton = new JButton("Metal");
private JButton motifButton = new JButton("Motif");
private JButton windowsButton = new JButton("Windows");
private JButton macButton = new JButton("Mac");
public LookAndFeel() {
add(metalButton);
add(motifButton);
add(windowsButton);
add(macButton);
metalButton.addActionListener(this);
motifButton.addActionListener(this);
windowsButton.addActionListener(this);
macButton.addActionListener(this);
}
public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
String plaf = "";
if (source == metalButton)
plaf = "javax.swing.plaf.metal.MetalLookAndFeel";
else if (source == motifButton)
plaf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
else if (source == windowsButton)
plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
else if (source == macButton)
plaf = "javax.swing.plaf.mac.MacLookAndFeel.Mac";
try {
UIManager.setLookAndFeel(plaf);
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) {
}
}
}Gostei + 0
09/04/2009
Carlos Heuberger
...
try {
UIManager.setLookAndFeel(plaf);
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) {
e.printStackTrace();
}
...Gostei + 0
09/04/2009
Davi Pereira
Gostei + 0
16/01/2010
Davi Pereira
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)