Problem mit Validierende Eingabefeldern JFormattedTextField

Status
Nicht offen für weitere Antworten.
Hab da ein Problem mit dem JFormattedTextField. Wer kann helfen?
Beim Compilieren kommt kein Fehler!! Und bei der Ausführung kommt nur ein kleiner Spalt, wo aber nix einzutragen geht. Das Caret erscheint aber.

Code:
....

public class Kugel extends JFrame
{
	public Kugel ()
	{
		// Fenstereigenschaften
		super ("Kugel");
		setSize (800, 400);
		setLayout (new GridLayout (4, 1));
		
		// Panels
		JPanel titel = new JPanel();
		JPanel durchmesser = new JPanel();
		JPanel berechnen = new JPanel();
		JPanel button = new JPanel();
		
                                ....
				
		// Textfeld
		JFormattedTextField tf = new JFormattedTextField (new DecimalFormat ("#,###"));
		
		// Belegung der Panels
		titel.add (titela);
		durchmesser.add (durchmessera);
		durchmesser.add (tf);
		berechnen.add (berechnena);
		button.add (zurueck);
		button.add (beenden);
		
		// Einfügen der Panels
		add (titel);
		add (durchmesser);
		add (berechnen);
		add (button);
		
		// Sichtbarkeit des Fensters
		setVisible (true);
		
		// Einbinden der Buttons in den ActionListener
		zurueck.addActionListener (a1);
		beenden.addActionListener (a1);
		berechnena.addActionListener (a1);
		tf.addActionListener (a1);
	}
	
	ActionListener a1 = new ActionListener()
	{
	public void actionPerformed(ActionEvent a)
	{	
	
		....
		
		System.out.println ( ((JFormattedTextField)a.getSource()).getText() );
	}
	};
}
 
Soll heißen: sieh dir die setColumns Methode der Klasse an. Wenn du da einen Wert übergibst nimmt das JFormattedTextField eine bestimmte Breite ein.
 
Ahh, Danke hab es gefunden!

Code:
JFormattedTextField tf = new JFormattedTextField (new DecimalFormat("#,###",20));

Problem ist nur jetzt kommt eine Fehlermeldung!! Und zwar folgende:
C:\Dokumente und Einstellungen\epimetheus_xxx\Desktop\Beleg SWT III\Kugel.java:41: cannot find symbol

symbol : constructor DecimalFormat(java.lang.String,int)

location: class java.text.DecimalFormat

JFormattedTextField tf = new JFormattedTextField (new DecimalFormat("",20));
^
 
DecimalFormat hat keinen solchen Konstruktor. Meinst du vielleicht
Code:
JFormattedTextField tf = new JFormattedTextField (new DecimalFormat("#,###"),20);
?
 
Hatte ich auch schon ausprobiert, aber dann kommt das:
C:\Dokumente und Einstellungen\epimetheus_xxx\Desktop\Beleg SWT III\Kugel.java:41: cannot find symbol

symbol : constructor JFormattedTextField(java.text.DecimalFormat,int)

location: class javax.swing.JFormattedTextField

JFormattedTextField tf = new JFormattedTextField (new DecimalFormat("#,##"),20);

^
 
ok, war zu faul in die API zu schauen. Mach's einfach so wie ich gesagt habe:
Code:
JFormattedTextField tf = new JFormattedTextField (new DecimalFormat("#,###"));
tf.setColumns(20);
Kannst du jetzt etwas eingeben?
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben