Mudando o "desenho" do JButton

4 respostas
RicardoCobain

Olá galera GUJ !

Estou querendo adicionar um JButton em um componente chamdo JXStatusBar (Do SwingX),
ele funciona como se fosse um JPanel(deve estender ele), só que eu não queria que ele ficasse com o estilo convencianal…
Teria como deixar ele da mesma forma que ele fica quando adicionado em um JToolBar ?!

ex:

4 Respostas

Leandro_R_Combinato

Ola Ricardo vou te passa uma maneira convencional … axo q issu vai te ajuda colega! boa sorte!!!

package Projeto;

import java.awt.Container;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyAdapter;

import java.awt.event.KeyEvent;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.*;

public class  JanPrincipal {

JFrame janela;

JPanel panel;

JMenuBar barraMenu;

JMenu menuCadastro;

JMenuItem opDiversas,opIncluir1,opAlterar1,opExcluir1,opConsultar1;

JButton opEtiquetas01,opEtiquetas02,opSair;
ImageIcon pathImagem;
JLabel imagem;

String path = "J:/Textil/";
String path2 = "C:/eclipse/workspace/";


public JanPrincipal() {
	janela = new JFrame();
	janela.setTitle("Janela Principal");
	panel = new JPanel();
	panel.setLayout(null);
	janela.addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent e)
		{
			System.exit(0); // fecha e sai do programa
		}
	});
	barraMenu = new JMenuBar();
	menuCadastro = new JMenu("Cadastro");
	menuCadastro.setMnemonic(KeyEvent.VK_C);
	barraMenu.add(menuCadastro);
	opDiversas = new JMenu ("Etiquetas Diversas");
	opDiversas.setMnemonic(KeyEvent.VK_Q);
	menuCadastro.add(opDiversas);
	opIncluir1 = new JMenuItem ("Incluir");
	opIncluir1.setMnemonic(KeyEvent.VK_I);
	opDiversas.add(opIncluir1);
	opIncluir1.addActionListener (new ActionListener(){
		public void actionPerformed(java.awt.event.ActionEvent evt){
			try {
				JanEtiquetaDiversas jan = new JanEtiquetaDiversas(opIncluir1,null);
				janela.dispose();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	});
	opAlterar1 = new JMenuItem ("Alterar");
	opAlterar1.setMnemonic(KeyEvent.VK_A);
	opDiversas.add(opAlterar1);
	opAlterar1.addActionListener (new ActionListener(){
		public void actionPerformed(java.awt.event.ActionEvent evt){
			try {
				JanEtiquetaDiversas jan = new JanEtiquetaDiversas(null,opAlterar1);
				janela.dispose();
			} catch (Exception e) {
					e.printStackTrace();
			}
		}
	});
	opExcluir1 = new JMenuItem ("Excluir");
	opExcluir1.setMnemonic(KeyEvent.VK_E);
	opDiversas.add(opExcluir1);
	opExcluir1.addActionListener (new ActionListener(){
		public void actionPerformed(java.awt.event.ActionEvent evt){
			try {
				JanEtiquetaDiversas jan = new JanEtiquetaDiversas(null,null);
				janela.dispose();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	});
	opConsultar1 = new JMenuItem ("Consultar");
	opConsultar1.setMnemonic(KeyEvent.VK_C);
	opDiversas.add(opConsultar1);
	opConsultar1.addActionListener (new ActionListener(){
		public void actionPerformed(java.awt.event.ActionEvent evt){
			try {
				JanEtiquetaDiversas jan = new JanEtiquetaDiversas(null,null);
				janela.dispose();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	});
	
	
	
	opDiversas = new JMenu ("Etiquetas Chenille");
	opDiversas.setMnemonic(KeyEvent.VK_Q);
	menuCadastro.add(opDiversas);
	opIncluir1 = new JMenuItem ("Incluir");
	opIncluir1.setMnemonic(KeyEvent.VK_I);
	opDiversas.add(opIncluir1);
	opIncluir1.addActionListener (new ActionListener(){
		public void actionPerformed(java.awt.event.ActionEvent evt){
			try {
				JanEtiquetaChenille jan = new JanEtiquetaChenille(opIncluir1,null);
				janela.dispose();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	});
	opAlterar1 = new JMenuItem ("Alterar");
	opAlterar1.setMnemonic(KeyEvent.VK_A);
	opDiversas.add(opAlterar1);
	opAlterar1.addActionListener (new ActionListener(){
		public void actionPerformed(java.awt.event.ActionEvent evt){
			try {
				JanEtiquetaChenille jan = new JanEtiquetaChenille(null,opAlterar1);
				janela.dispose();
			} catch (Exception e) {
					e.printStackTrace();
			}
		}
	});
	opExcluir1 = new JMenuItem ("Excluir");
	opExcluir1.setMnemonic(KeyEvent.VK_E);
	opDiversas.add(opExcluir1);
	opExcluir1.addActionListener (new ActionListener(){
		public void actionPerformed(java.awt.event.ActionEvent evt){
			try {
				JanEtiquetaChenille jan = new JanEtiquetaChenille(null,null);
				janela.dispose();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	});
	opConsultar1 = new JMenuItem ("Consultar");
	opConsultar1.setMnemonic(KeyEvent.VK_C);
	opDiversas.add(opConsultar1);
	opConsultar1.addActionListener (new ActionListener(){
		public void actionPerformed(java.awt.event.ActionEvent evt){
			try {
				JanEtiquetaChenille jan = new JanEtiquetaChenille(null,null);
				janela.dispose();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	});

	
	
	opEtiquetas01 = new JButton("Etiquetas Diversas ");
	opEtiquetas01.setMnemonic(KeyEvent.VK_L);
	opEtiquetas01.setBounds(10,50,150,30);
	panel.add(opEtiquetas01);
	opEtiquetas01.addActionListener (new ActionListener(){
		public void actionPerformed(ActionEvent evt1){
			botaoEtiquetas01(evt1, null);
		}
	});
	opEtiquetas01.addKeyListener(new KeyAdapter(){
        public void keyPressed(KeyEvent evt2) {
    	int keyCode = evt2.getKeyCode();
       		if(keyCode == KeyEvent.VK_ENTER){
       			botaoEtiquetas01(null, evt2);
       		}
    }});
	
	opEtiquetas02 = new JButton("Etiquetas Chenille ");
	opEtiquetas02.setMnemonic(KeyEvent.VK_L);
	opEtiquetas02.setBounds(10,100,150,30);
	panel.add(opEtiquetas02);
	opEtiquetas02.addActionListener (new ActionListener(){
		public void actionPerformed(ActionEvent evt1){
			botaoEtiquetas02(evt1, null);
		}
	});
	opEtiquetas02.addKeyListener(new KeyAdapter(){
        public void keyPressed(KeyEvent evt2) {
    	int keyCode = evt2.getKeyCode();
       		if(keyCode == KeyEvent.VK_ENTER){
       			botaoEtiquetas02(null, evt2);
       		}
    }});
	
	opSair = new JButton("Sair");
	opSair.setMnemonic(KeyEvent.VK_S);
	opSair.setBounds(10,150,60,30);
	panel.add(opSair);
	opSair.addActionListener (new ActionListener(){
		public void actionPerformed(ActionEvent evt1){
			botaoSair(evt1, null);

		}
	});
	opSair.addKeyListener(new KeyAdapter(){
        public void keyPressed(KeyEvent evt2) {
    	int keyCode = evt2.getKeyCode();
       		if(keyCode == KeyEvent.VK_ENTER){
       			botaoSair(null, evt2); 
      		}
    }});
	
	pathImagem = new ImageIcon(path+"TextilETQGUI/Imagem/Logotipo.gif");
	imagem = new JLabel(pathImagem);
	imagem.setBounds(200,180,600,300);
	panel.add(imagem);
	
	Container c = janela.getContentPane();
	c.add(panel);
	janela.setJMenuBar(barraMenu);
	janela.setSize(1024,735);
	janela.setVisible(true);
}

}

RicardoCobain

Bem grandinho o codigo heim… hehehe
não deu pra compilar pq falatava algumas coisas…

Analizei ele e não vi nada sobre como mudar o “estilo” do botao em si…
só como add imagens neles… mas isso eu sei !

O que eu quero que que o botao se comporte no JXStatusBar da mesma forma que ele se comporta no JToolBar.
ex: No começo só aparece o Texto ai quando o cara coloca o mouse por cima ele ganha o contorno do botao…

mas vlw pela ajuda.
quem souber ainda tou com esse problema…

Leandro_R_Combinato

E ai gente boa, por favor compila esse codigo, ele funciona bonitinho, o a imagem q nao vai aparece mais vc pode coloca outra, blza … JMenuBar é um menu convencional, valeu!

import java.awt.Container;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.KeyAdapter;

import java.awt.event.KeyEvent;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import javax.swing.*;

public class JanPrincipal {

JFrame janela;

JPanel panel;

JMenuBar barraMenu;

JMenu menuCadastro;

JMenuItem opDiversas,opIncluir1,opAlterar1,opExcluir1,opConsultar1;

JButton opEtiquetas01,opEtiquetas02,opSair;
ImageIcon pathImagem; 
JLabel imagem; 

String path = "J:/Textil/"; 
String path2 = "C:/eclipse/workspace/"; 


public JanPrincipal() { 
	janela = new JFrame(); 
	janela.setTitle("Janela Principal"); 
	panel = new JPanel(); 
	panel.setLayout(null); 
	janela.addWindowListener(new WindowAdapter() { 
		public void windowClosing(WindowEvent e) 
		{ 
			System.exit(0); // fecha e sai do programa 
		} 
	}); 
	barraMenu = new JMenuBar(); 
	menuCadastro = new JMenu("Cadastro"); 
	menuCadastro.setMnemonic(KeyEvent.VK_C); 
	barraMenu.add(menuCadastro); 
	opDiversas = new JMenu ("Etiquetas Diversas"); 
	opDiversas.setMnemonic(KeyEvent.VK_Q); 
	menuCadastro.add(opDiversas); 
	opIncluir1 = new JMenuItem ("Incluir"); 
	opIncluir1.setMnemonic(KeyEvent.VK_I); 
	opDiversas.add(opIncluir1); 
	opIncluir1.addActionListener (new ActionListener(){ 
		public void actionPerformed(java.awt.event.ActionEvent evt){ 
			try { 
			} catch (Exception e) { 
				e.printStackTrace(); 
			} 
		} 
	}); 
	opAlterar1 = new JMenuItem ("Alterar"); 
	opAlterar1.setMnemonic(KeyEvent.VK_A); 
	opDiversas.add(opAlterar1); 
	opAlterar1.addActionListener (new ActionListener(){ 
		public void actionPerformed(java.awt.event.ActionEvent evt){ 
			try { 
			} catch (Exception e) { 
				e.printStackTrace(); 
			} 
		} 
	}); 
	opExcluir1 = new JMenuItem ("Excluir"); 
	opExcluir1.setMnemonic(KeyEvent.VK_E); 
	opDiversas.add(opExcluir1); 
	opExcluir1.addActionListener (new ActionListener(){ 
		public void actionPerformed(java.awt.event.ActionEvent evt){ 
			try { 
			} catch (Exception e) { 
				e.printStackTrace(); 
			} 
		} 
	}); 
	opConsultar1 = new JMenuItem ("Consultar"); 
	opConsultar1.setMnemonic(KeyEvent.VK_C); 
	opDiversas.add(opConsultar1); 
	opConsultar1.addActionListener (new ActionListener(){ 
		public void actionPerformed(java.awt.event.ActionEvent evt){ 
			try { 
			} catch (Exception e) { 
				e.printStackTrace(); 
			} 
		} 
	}); 
	
	
	
	opDiversas = new JMenu ("Etiquetas Chenille"); 
	opDiversas.setMnemonic(KeyEvent.VK_Q); 
	menuCadastro.add(opDiversas); 
	opIncluir1 = new JMenuItem ("Incluir"); 
	opIncluir1.setMnemonic(KeyEvent.VK_I); 
	opDiversas.add(opIncluir1); 
	opIncluir1.addActionListener (new ActionListener(){ 
		public void actionPerformed(java.awt.event.ActionEvent evt){ 
			try { 
			} catch (Exception e) { 
				e.printStackTrace(); 
			} 
		} 
	}); 
	opAlterar1 = new JMenuItem ("Alterar"); 
	opAlterar1.setMnemonic(KeyEvent.VK_A); 
	opDiversas.add(opAlterar1); 
	opAlterar1.addActionListener (new ActionListener(){ 
		public void actionPerformed(java.awt.event.ActionEvent evt){ 
			try { 
			} catch (Exception e) { 
				e.printStackTrace(); 
			} 
		} 
	}); 
	opExcluir1 = new JMenuItem ("Excluir"); 
	opExcluir1.setMnemonic(KeyEvent.VK_E); 
	opDiversas.add(opExcluir1); 
	opExcluir1.addActionListener (new ActionListener(){ 
		public void actionPerformed(java.awt.event.ActionEvent evt){ 
			try { 
			} catch (Exception e) { 
				e.printStackTrace(); 
			} 
		} 
	}); 
	opConsultar1 = new JMenuItem ("Consultar"); 
	opConsultar1.setMnemonic(KeyEvent.VK_C); 
	opDiversas.add(opConsultar1); 
	opConsultar1.addActionListener (new ActionListener(){ 
		public void actionPerformed(java.awt.event.ActionEvent evt){ 
			try { 
			} catch (Exception e) { 
				e.printStackTrace(); 
			} 
		} 
	}); 
	
	
	
	opEtiquetas01 = new JButton("Etiquetas Diversas "); 
	opEtiquetas01.setMnemonic(KeyEvent.VK_L); 
	opEtiquetas01.setBounds(10,50,150,30); 
	panel.add(opEtiquetas01); 
	opEtiquetas01.addActionListener (new ActionListener(){ 
		public void actionPerformed(ActionEvent evt1){
//				botaoEtiquetas01(evt1, null);

}

});

opEtiquetas01.addKeyListener(new KeyAdapter(){

public void keyPressed(KeyEvent evt2) {

int keyCode = evt2.getKeyCode();

if(keyCode == KeyEvent.VK_ENTER){

//					botaoEtiquetas01(null, evt2);

}

}});
opEtiquetas02 = new JButton("Etiquetas Chenille "); 
	opEtiquetas02.setMnemonic(KeyEvent.VK_L); 
	opEtiquetas02.setBounds(10,100,150,30); 
	panel.add(opEtiquetas02); 
	opEtiquetas02.addActionListener (new ActionListener(){ 
		public void actionPerformed(ActionEvent evt1){
//				botaoEtiquetas02(evt1, null);

}

});

opEtiquetas02.addKeyListener(new KeyAdapter(){

public void keyPressed(KeyEvent evt2) {

int keyCode = evt2.getKeyCode();

if(keyCode == KeyEvent.VK_ENTER){

//					botaoEtiquetas02(null, evt2);

}

}});
opSair = new JButton("Sair"); 
	opSair.setMnemonic(KeyEvent.VK_S); 
	opSair.setBounds(10,150,60,30); 
	panel.add(opSair); 
	opSair.addActionListener (new ActionListener(){ 
		public void actionPerformed(ActionEvent evt1){

// botaoSair(evt1, null);

} 
	}); 
	opSair.addKeyListener(new KeyAdapter(){ 
		public void keyPressed(KeyEvent evt2) { 
			int keyCode = evt2.getKeyCode(); 
			if(keyCode == KeyEvent.VK_ENTER){
//					botaoSair(null, evt2);

}

}});
pathImagem = new ImageIcon(path+"TextilETQGUI/Imagem/Logotipo.gif"); 
	imagem = new JLabel(pathImagem); 
	imagem.setBounds(200,180,600,300); 
	panel.add(imagem); 
	
	Container c = janela.getContentPane(); 
	c.add(panel); 
	janela.setJMenuBar(barraMenu); 
	janela.setSize(1024,735); 
	janela.setVisible(true); 
}

public static void main(String arg[]){
	JanPrincipal jan = new JanPrincipal(); 
	
}

}

romulo_wan

como posso estender a largura pro tamanho do Frame??
tipo tenho u menu e quero q o jToolbar fique da largura do mesmo.

Criado 10 de setembro de 2007
Ultima resposta 1 de jun. de 2011
Respostas 4
Participantes 3