Alterar padrão do JTextField

Estou desenvolvendo algumas telas utilizando o Swing e gostaria de por exemplo
todo JTextField que eu use ele por padrão vir com bordas já, como faço para alterar isso?
Não gostaria de criar uma classe e utilzar o extends, e sim alterar o padrão mesmo, tem como?
Parece que existe o swing.properties… seria nele?

muito obrigado.

Você pode usar um look&feel configurável.

https://substance.dev.java.net/

“Não gostaria de criar uma classe e utilzar o extends”

Entao passe a gostar. Dificilmente vc vai usar componentes puros do Swing.
Falo por experiencia propria.
Extenda, mesmo se nao for customizar nada agora. DEPOIS vc pode querer customizar (e acredite, vc vai)

É sempre bom construir uma “infra”, com suas classes (textfield, combo, renderer, table, etc…) e com os comportamentos/aparencia necessarios.

Uma coisa que é sempre bom ter na sua caixa de ferramentas são 4 classes que estendem JTextField:

  • Uma que permita entrar com valores monetários, e vá formatando enquanto você vai digitando
  • Uma que permita entrar com datas
  • Uma que permita entrar com CPF
  • Uma que permita entrar com CNPJ

Não faça a besteira de usar JFormattedTextField para tudo. O comportamento de um JFormattedTextField não é prático para o usuário final, e você vai ter vários problemas.

Outra coisa é aprender a usar o Glazed Lists para usar com JTables, e o MiG Layout em vez de ficar brigando com os layouts do AWT/Swing.

[quote=thingol]Uma coisa que é sempre bom ter na sua caixa de ferramentas são 4 classes que estendem JTextField:

  • Uma que permita entrar com valores monetários, e vá formatando enquanto você vai digitando
  • Uma que permita entrar com datas
  • Uma que permita entrar com CPF
  • Uma que permita entrar com CNPJ

Não faça a besteira de usar JFormattedTextField para tudo. O comportamento de um JFormattedTextField não é prático para o usuário final, e você vai ter vários problemas.[/quote]

Eu estou exatamente a procura disso amigo. Será que vc poderia me ajudar com esses formatos dinâmicos?

Completando a dica do Thingol, aconselho a vc DOMINAR essas duas classes:
http://java.sun.com/javase/6/docs/api/javax/swing/InputVerifier.html
e
http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/PlainDocument.html

E em relação a esses formatos(CPF,CNPJ…) faça uma busca aqui mesmo no GUJ que vc encontrará muita coisa pronta.

Usa o LookAndFeel Nimbus, ele vei as bordas com um aparencia bem legal e futurista.

Tipo: Cria um metodo assim

public void lookAndFeel(){
try {
UIManager.setLookAndFeel(look);
} catch (Exception e) {
e.printStackTrace();
}
}

Agoa antes de carregar a sua tela você faz asim:
String look = “com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel”;

Dessa forma toda a sua aplicação vai ficar fantastica.
Mas esse LookAndFeel se não me engano ele só tem na verção 6 do JDK.

Valeu.

Valeu pessoal pelas dicas, e mais do que isso… a atenção.

Giliard, fiz um teste aqui com o Nimbus muito legal mesmo, segue o código para
quem quiser ver:

/****************************************************************/
/*                      Cad001	                            */
/*                                                              */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
/**
 * Summary description for Cad001
 *
 */
public class Cad001 extends JDialog
{
	// Variables declaration
	private JTabbedPane jTabbedPane1;
	private JPanel contentPane;
	//-----
	private JPanel Painel_Botoes;
	//-----
	private JPanel jPanel3;
	//-----
	private JPanel jPanel4;
	//-----
	private JPanel jPanel6;
	//-----
	private JTextField jTextField1;
	private JPanel jPanel8;
	//-----
	private JPanel jPanel9;
	//-----
	// End of variables declaration


	public Cad001(Frame w)
	{
		super(w);
		initializeComponent();
		//
		// TODO: Add any constructor code after initializeComponent call
		//

		this.setVisible(true);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always regenerated
	 * by the Windows Form Designer. Otherwise, retrieving design might not work properly.
	 * Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
	 * to retrieve your design properly in future, before revising this method.
	 */
	private void initializeComponent()
	{
		jTabbedPane1 = new JTabbedPane();
		contentPane = (JPanel)this.getContentPane();
		//-----
		Painel_Botoes = new JPanel();
		//-----
		jPanel3 = new JPanel();
		//-----
		jPanel4 = new JPanel();
		//-----
		jPanel6 = new JPanel();
		//-----
		jTextField1 = new JTextField();
		jPanel8 = new JPanel();
		//-----
		jPanel9 = new JPanel();
		//-----

		//
		// jTabbedPane1
		//
		jTabbedPane1.addTab("jPanel3", jPanel3);
		jTabbedPane1.addTab("jPanel4", jPanel4);
		jTabbedPane1.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e)
			{
				jTabbedPane1_stateChanged(e);
			}

		});
		//
		// contentPane
		//
		contentPane.setLayout(new BorderLayout(0, 0));
		contentPane.add(Painel_Botoes, BorderLayout.SOUTH);
		contentPane.add(jTabbedPane1, BorderLayout.CENTER);
		//
		// Painel_Botoes
		//
		Painel_Botoes.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		Painel_Botoes.setPreferredSize(new Dimension(50, 50));
		//
		// jPanel3
		//
		jPanel3.setLayout(new BorderLayout(0, 0));
		jPanel3.add(jPanel6, BorderLayout.SOUTH);
		jPanel3.add(jPanel8, BorderLayout.NORTH);
		jPanel3.add(jPanel9, BorderLayout.CENTER);
		jPanel3.setBorder(BorderFactory.createLoweredBevelBorder());
		//
		// jPanel4
		//
		jPanel4.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		jPanel4.setBorder(BorderFactory.createLoweredBevelBorder());
		//
		// jPanel6
		//
		jPanel6.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		jPanel6.setBorder(new TitledBorder("Title"));
		jPanel6.setPreferredSize(new Dimension(60, 60));
		//
		// jTextField1
		//
		jTextField1.setText("jTextField1");
		jTextField1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				jTextField1_actionPerformed(e);
			}

		});
		//
		// jPanel8
		//
		jPanel8.setLayout(null);
		jPanel8.setBorder(new TitledBorder("Title"));
		jPanel8.setPreferredSize(new Dimension(60, 60));
		addComponent(jPanel8, jTextField1, 88,23,178,22);
		//
		// jPanel9
		//
		jPanel9.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		jPanel9.setBorder(new TitledBorder("Title"));
		//
		// Cad001
		//
		this.setTitle("Cad001 - extends JDialog");
		this.setLocation(new Point(10, 10));
		this.setSize(new Dimension(443, 368));
	}

	/** Add Component Without a Layout Manager (Absolute Positioning) */
	private void addComponent(Container container,Component c,int x,int y,int width,int height)
	{
		c.setBounds(x,y,width,height);
		container.add(c);
	}

	//
	// TODO: Add any appropriate code in the following Event Handling Methods
	//
	private void jTabbedPane1_stateChanged(ChangeEvent e)
	{
		System.out.println("\njTabbedPane1_stateChanged(ChangeEvent e) called.");
		// TODO: Add any handling code here

	}

	private void jTextField1_actionPerformed(ActionEvent e)
	{
		System.out.println("\njTextField1_actionPerformed(ActionEvent e) called.");
		// TODO: Add any handling code here

	}

	//
	// TODO: Add any method code to meet your needs in the following area
	//






























 

//============================= Testing ================================//
//=                                                                    =//
//= The following main method is just for testing this class you built.=//
//= After testing,you may simply delete it.                            =//
//======================================================================//
	public static void main(String[] args)
	{
		JFrame.setDefaultLookAndFeelDecorated(true);
		JDialog.setDefaultLookAndFeelDecorated(true);
		try
		{
			//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
			UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
			
			
		}
		catch (Exception ex)
		{
			System.out.println("Failed loading L&F: ");
			System.out.println(ex);
		}
		final JFrame w = new JFrame("Owner Window");
		JButton btn = new JButton("Show Dialog");
		btn.addActionListener(new java.awt.event.ActionListener() {
							public void actionPerformed(java.awt.event.ActionEvent e)
							{
								//-- Create a Cad001 --
								new Cad001(w);
								//-------------------
							}});
		JPanel p = new JPanel();
		p.add(btn);
		w.getContentPane().add(p);
		w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		w.setSize(500,360);
		w.setLocation(150,36);
		w.setVisible(true);
	}
//= End of Testing =


}

me corrijam se eu estiver errado, mas não ficou igual a um JInternalFrame?