The Artima Developer Community
Sponsored Link

Java Answers Forum
How to access JSpinner's JTextField?

1 reply on 1 page. Most recent reply: Nov 4, 2004 4:09 AM by prakie

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Gibran Shah

Posts: 27
Nickname: gibby
Registered: Jun, 2004

How to access JSpinner's JTextField? Posted: Oct 30, 2004 7:08 AM
Reply to this message Reply
Advertisement
Hello,

I'm working with a JSpinner and I need to set its' focus with a call to requestFocusInWindow(), but I forget how to get access to its' JTextField. I've tried saying "Spinner.requestFocusInWindow()" but that doesn't seem to do anything and I know the JSpinner has a JTextField which it uses to display and edit the value. I'd like to make a call like "Spinner.getTextField().requestFocusInWindow()" but I don't remember how to gain access to the JTextField (the aformentioned quote doesn't work). Does anybody know how to do this?

Gib


prakie

Posts: 2
Nickname: prakie
Registered: Nov, 2004

Re: How to access JSpinner's JTextField? Posted: Nov 4, 2004 4:09 AM
Reply to this message Reply
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
import java.awt.*;
import java.util.*;

public class Spinner {
public static void main (String args[]) throws Exception {
JFrame frame = new JFrame("Spinner");
frame.setDefaultCloseOperation(3);
String[] months = new DateFormatSymbols().getMonths();
SpinnerModel model = new SpinnerListModel(months);
JSpinner spinner = new JSpinner(model);
frame.getContentPane().add(spinner, BorderLayout.NORTH);

SpinnerDateModel model2 = new SpinnerDateModel();
model2.setCalendarField(Calendar.WEEK_OF_MONTH);
JSpinner spinner2 = new JSpinner(model2);
JSpinner.DateEditor editor2 = new JSpinner.DateEditor(spinner2, "MMMMM dd, yyyy");
spinner2.setEditor(editor2);
frame.getContentPane().add(spinner2, BorderLayout.SOUTH);

SpinnerNumberModel model3 = new SpinnerNumberModel(50, 0, 100, 5);
JSpinner spinner3 = new JSpinner(model3);
frame.getContentPane().add(spinner3, BorderLayout.CENTER);

ChangeListener listener = new ChangeListener() {
public void stateChanged(ChangeEvent e) {
SpinnerModel source = (SpinnerModel)e.getSource();
System.out.println("The value is: " + source.getValue());
}
};
model.addChangeListener(listener);
model2.addChangeListener(listener);
model3.addChangeListener(listener);

frame.pack();
frame.show();
}
}

Flat View: This topic has 1 reply on 1 page
Topic: Launch browser from java Previous Topic   Next Topic Topic: about  JCP exam !

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use