JSpinner

Hi,
I have a JSpinner placed in my Jframe displaying the current date and time.I want to write a Sql query to display data according to the from date and To date displayed using JSPinner.But the date format in my oracle database is different from what Jspinner is displaying.How to do that?Pls.Help.
Thanks,
AArthy

Braim,
JSpinner is available in Jdeveloper 9.0.4 (not out yet) and JDeveloper 9.0.5 (aka 10g, planned for january 2004). Until then there is no JSpinner binding support in JClient.
Frank

Similar Messages

  • Memory leak in JSpinner implementation (maybe others?)

    Hi,
    I am developing an application using Java and Swing, and have run into some problems with memory leaks. After examining the source code and making an example program (provided below), I can only come to the conclusion that there is a bug in the implementation of JSpinner in Sun Java 1.6.0_03.
    If one uses a custom model with the JSpinner, it attaches itself as a listener to the model. However, it never removes the listening connection, even if the model is changed. This causes the JSpinner to be kept in memory as long as the model exists, even if all other references to the component have been removed.
    An example program is available at http://eddie.dy.fi/~sampo/ModelTest.java . It is a simple swing program that has the JSpinner and two buttons, the first of which writes to stdout the listeners of the original model and the second changes the spinner model to a newly-created model. A sample output is below:
    Running on 1.6.0_03 from Sun Microsystems Inc.
    Listeners before connecting to JSpinner:
      Model value is 0, 0 listeners connected:
    Listeners after connecting to JSpinner:
      Model value is 0, 2 listeners connected:
      1: interface javax.swing.event.ChangeListener
      2: javax.swing.JSpinner$ModelListener@9971ad
    Listeners now:
      Model value is 8, 2 listeners connected:
      1: interface javax.swing.event.ChangeListener
      2: javax.swing.JSpinner$ModelListener@9971ad
    Changing spinner model.
    Listeners now:
      Model value is 8, 2 listeners connected:
      1: interface javax.swing.event.ChangeListener
      2: javax.swing.JSpinner$ModelListener@9971adThis shows that even though the model of the JSpinner has been changed, it still listens to the original model. I haven't looked at other components whether they retain connections to the old models as well.
    In my case, I have an adaptor-model which provides a SpinnerModel interface to the actual data. The adaptor is implemented so that it listens to the underlying model only when it itself is being listened to. If the JComponents using the model were to remove the listening connections, it, too, would be automatically garbage-collected. However, since JSpinner does not remove the connections, the adaptor also continues to listen to the underlying model, and neither can be garbage-collected.
    All in all, the listener-connections seem to be a very easy place to make memory leaks in Java and especially in Swing. However, as I see it, it would be a simple matter to make everything work automatically with one simple rule: Listen to the models only when necessary.
    If a component is hidden (or alternatively has no contact to a parent JFrame or equivalent), it does not need to listen to the model and should remove the connections. When the component is again set visible (or connected to a frame) it can re-add the connections and re-read the current model values just as it does when initializing the component. Similarly, any adaptor-models should listen to the underlying model only when it itself is being listened to.
    If the components were implemented in this way, one could simply remove a component from the frame and throw it away, and automatically any listener-connections will be removed and it can be garbage-collected. Similarly any adaptor-models are collected when they are no longer in use.
    Changing the API implementation in this way would not require any changes to applications, as the only thing that changes are the listener-connections. Currently used separate connection-removing methods should still work, though they would be unnecessary any more. The API would look exactly the same from the view of an application programmer, only that she would not need to care about remnant listening connections. (As far as I can tell, the current API specification would allow the API to be implemented as described above, but it should of course require it to be implemented in such a way.)
    Am I missing something, or is there some valid reason why the API is not implemented like this?
    PS. I'm new to these forums, so if there is a better place to post these reports, please tell me. Thanks.

    Another cognition: It's the following code, that causes the memory to be accumulated:
    obj = m_orb.resolve_initial_references("NameService");
    ctx = NamingContextExtHelper.narrow(obj);For the first 4 calls to this code the memory usage of the nameservice is unchanged. From the 5th to the 8th call, it's increased by approx. 10KB per call. And thenceforward (beginning with the 9th call) it's increasing by approx. 10MB.
    What's going wrong here?

  • Can't make an alarm that is set more than 24 hours in future with JSpinner

    I have what I thought was a simple problem, but I can't seem to get past it, so I come to ask the experts.
    I want to use a JSpinner to basically set an alarm. I am using the SpinnerDateModel and a DateEditor with the string "HHH:mm:ss". The reason there is three hour feilds is because what I really want is to be able to set it to any number of hours from 0 to 999. But there in lies my problem, it won't let me get past 24.
    What I have tried:
    I changed the first H to D (or d, whichever is days in the year) but it wont work for me because it can't be zero.
    I tried extending the DateEditor code, but this was next to impossible because the company I work for makes us have two machines on our desk, both are thin clients, one connects to the internet but we are not allowed/able to download anything, and it does not have java on it in any form. The other does not connect to the internet, and can not, it has Java on it, but not the source code for methods like DateEditor. So without seeing the source I have no clue what to override.
    I really want to use the one JSpinner with the SpinnerDateModel, but if I can't figure this out then I could use seperate spinners for hours, minutes, and seconds though that looks really ugly and is far from ideal.
    So please if anyone has any clue how I could solve this, please let me know.
    Thanks,
    JSG
    Edited by: JustSomeGuy on Jun 29, 2010 2:00 PM

    I just tried out a JSpinner with the SpinnerDateModel and DateEditor using pattern "HH:mm:ss". Behind the scenes, you are still dealing with a date. If you look at what date gets returned, the first time you spin the spinner using that pattern, the year suddenly jumps to 1970. It's using a default year, because there is no year to spin within your pattern.
    So long as you don't feel too guilty or uncool for using the date spinner in a manner that it was not intended, you could probably achieve your objective by abusing the date editor with a pattern like "SSS:mm:ss". That pattern is milliseconds (which conveniently go from 0 to 999), minutes, then seconds. When reading your spinner, just interpret the milliseconds as the hours, minutes as minutes, and seconds as seconds. The rest of the date just gets thrown away. Uncool. But should work.
    Or you can be cool and write a custom editor and model, but depending on your experience level, this could be difficult and time consuming. But also comes with a greater feeling of achievement.

  • How to set numeric filter for JSpinner?

    Hi there,
    I searched the forum but can't find a solution...I'm kind of getting mad!
    Problem is: I have a JSpinner, I must prevent the user to insert any non-numeric value. the accepted input should be in the form <n>.<m>
    where n could be any integer number, m is OPTIONAL and could be a single digit number. Example: 150.2 or 41 or 7.1 etc.
    I set a DocumentFilter on the editor of JSpinner, overriding replace method. Problem is replace method is never called so my filter is not applied and the user is allowed to insert whatever he wants, characters included.
    Here's my code (sorry for the horrible gui, but it's just for some testing.):
    import java.awt.Dimension;
    import java.util.regex.Pattern;
    import javax.swing.JFrame;
    import javax.swing.JSpinner;
    import javax.swing.JTextField;
    import javax.swing.SpinnerNumberModel;
    import javax.swing.JSpinner.NumberEditor;
    import javax.swing.text.AbstractDocument;
    import javax.swing.text.AttributeSet;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.DocumentFilter;
    public class SpinnerTry {
         public final static String REGEX_DOUBLE_NUMBER = "^([0-9]+)(\\.(\\d{1})?)?$";
         private static final Double MIN_PW = 12.0;
         private static final Double MAX_PW = 19.0;
         private static final Double DEFAULT = 15.0;
         private static final Double STEP = 1.00;
         private static final SpinnerNumberModel model = new SpinnerNumberModel(
                   DEFAULT, // initial value
                   MIN_PW, // min
                   MAX_PW, // max
                   STEP);
         public static void main(String[] args) {
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JSpinner spinner = new JSpinner(model);
              spinner.setPreferredSize(new Dimension(50, 15));
              NumberEditor edit = new NumberEditor(spinner, "#######.#");
              spinner.setEditor(edit);
              JTextField textField = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
              ((AbstractDocument) textField.getDocument()).setDocumentFilter(new MyDocumentFilter());
              frame.getContentPane().add(spinner);
              frame.setSize(new Dimension(200, 200));
              frame.setVisible(true);
         static class MyDocumentFilter extends DocumentFilter {
              public void replace(FilterBypass fb, int offset, int length, String text,
                        AttributeSet attrs) throws BadLocationException {
                   System.out.println("Called replace");
                   String mytext = fb.getDocument().getText(0, offset);
                   mytext += text;
                   if (fb.getDocument().getLength() - 1 > offset) {
                        mytext += fb.getDocument().getText(offset + 1,
                                  fb.getDocument().getLength() - offset);
                   boolean ok = true;
                   ok = Pattern.matches(REGEX_DOUBLE_NUMBER, mytext);
                   if (ok)
                        super.replace(fb, offset, length, text, attrs);
              public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
                        throws BadLocationException {
                   if (Pattern.matches(REGEX_DOUBLE_NUMBER, string)) {
                        super.insertString(fb, offset, string, attr);
    }Why replace method is not called when inserting somethig into the spinner text field?
    Thanks a lot in advance.
    Paul
    Edited by: the.paul on Jul 27, 2010 1:11 AM

    I found a solution, got inspiration from [http://forums.sun.com/thread.jspa?forumID=57&threadID=5424330] .
    Code:
    import java.awt.Dimension;
    import java.text.DecimalFormat;
    import java.text.NumberFormat;
    import java.util.regex.Pattern;
    import javax.swing.JFrame;
    import javax.swing.JSpinner;
    import javax.swing.SpinnerNumberModel;
    import javax.swing.JSpinner.NumberEditor;
    import javax.swing.text.AttributeSet;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.DefaultFormatterFactory;
    import javax.swing.text.DocumentFilter;
    import javax.swing.text.NumberFormatter;
    public class SpinnerTry {
         public final static String REGEX_DOUBLE_NUMBER = "^([0-9]+)(\\.(\\d{1})?)?$";
         private static final Double MIN_PW = 12.0;
         private static final Double MAX_PW = 19.0;
         private static final Double DEFAULT = 15.0;
         private static final Double STEP = 1.00;
         private static final SpinnerNumberModel model = new SpinnerNumberModel(
                   DEFAULT, // initial value
                   MIN_PW, // min
                   MAX_PW, // max
                   STEP);
         public static void main(String[] args) {
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JSpinner spinner = new JSpinner(model);
              spinner.setPreferredSize(new Dimension(50, 15));
              String decimalFormatPattern = "#######.#";
              NumberEditor edit = new NumberEditor(spinner);
              spinner.setEditor(edit);
              ((NumberEditor) spinner.getEditor()).getTextField().setFormatterFactory(
                    new DefaultFormatterFactory(new MyListFormatter(model, new DecimalFormat(decimalFormatPattern))));
              frame.getContentPane().add(spinner);
              frame.setSize(new Dimension(200, 200));
              frame.setVisible(true);
         static class MyListFormatter extends NumberFormatter {
              private static final long serialVersionUID = -790552903800038787L;
              private final SpinnerNumberModel model;
              private DocumentFilter filter;
              MyListFormatter(SpinnerNumberModel model, NumberFormat format) {
                   super(format);
                   this.model = model;
                   setValueClass(model.getValue().getClass());
              public void setMinimum(Comparable min) {
                   model.setMinimum(min);
              public Comparable getMinimum() {
                   return model.getMinimum();
              public void setMaximum(Comparable max) {
                   model.setMaximum(max);
              public Comparable getMaximum() {
                   return model.getMaximum();
              protected DocumentFilter getDocumentFilter() {
                   if (filter == null) {
                        filter = new MyDocumentFilter();
                   return filter;
         static class MyDocumentFilter extends DocumentFilter {
              public void replace(FilterBypass fb, int offset, int length, String text,
                        AttributeSet attrs) throws BadLocationException {
                   System.out.println("Called replace");
                   String mytext = fb.getDocument().getText(0, offset);
                   mytext += text;
                   if (fb.getDocument().getLength() - 1 > offset) {
                        mytext += fb.getDocument().getText(offset + 1,
                                  fb.getDocument().getLength() - offset);
                   boolean ok = true;
                   ok = Pattern.matches(REGEX_DOUBLE_NUMBER, mytext);
                   if (ok)
                        super.replace(fb, offset, length, text, attrs);
              public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
                        throws BadLocationException {
                   if (Pattern.matches(REGEX_DOUBLE_NUMBER, string)) {
                        super.insertString(fb, offset, string, attr);
    }That is: define a custom formatter ; the formatter uses the custom DocumentFilter.
    Hope it is useful for some people out there.
    Regards

  • How to display the values in JSpinner in format  day:HH:mm

    Hi All,
    I want to know how can I display the values inside a JSpinner in the format day:HH:mm. Here the value of 'day' can be anything say from 0 to 365 and HH stand for hour and mm stands for minutes.
    I tried to implement it using
    mSpinner.setEditor(new JSpinner.DateEditor(mSpinner, "DD:HH:mm"));
    but here the values of day was not proper. Please let me know if there is any standard format or how can I configure my own editor.
    Thanks,
    Rohit.

    Hi,
    It worked well for 112 as 112 comes under April month.. i.e. it will work properly for the range 91 to 120 as the current month is April and if we start counting from january 01 then for April month , the number of day will fall under range 91 to 120.
    See, it will allow you to change the values beyond the limit (i.e. less than 91 or more than 120) but the real problem is that I used this spinner in the table and when I will try to save the value of spinner , then if the value of day in beyond the limit 91 to 120 then it will automatically changing in the range between 91 to 120.
    I tried to use format DD:HH:mm ...... do I need to use any other format..
    Hi All,
    I want to know how can I display the values inside
    de a JSpinner in the format day:HH:mm. Here thevalue
    of 'day' can be anything say from 0 to 365 and HH
    stand for hour and mm stands for minutes.
    I tried to implement it using
    mSpinner.setEditor(newJSpinner.DateEditor(mSpinner,
    , "DD:HH:mm"));
    but here the values of day was not proper. Define "not proper". I just tried it and it displayed
    day 112 for today which seems correct.

  • Read-only JSpinner?

    This may seem a little weird, but bear with me; I think the use case is valid.
    I am writing an abstract java.beans.Customizer that makes use of the JGoodies Binding framework, specifically the PresentationModel class. You need not know any details about this class except that it makes working with Java Beans properties very simple and allows many views to reflect changes in a common underlying model (the bean itself).
    Users of this Customizer who subclass it typically need to create some kind of Swing widget and bind it to a bean property, like so:
    this.bind(this.ageSpinner, "age");As I hope is clear this means bind the Customizer's bean property "age" to the ageSpinner component, which, for the sake of this question, let's assume is a JSpinner.
    Now, it just so happens that getAge() happens to be a computed property (that is, there is no setter).
    I would like it to be the case that if someone decides to bind a JSpinner to a read-only property that the spinner would not permit edits of any kind.
    I would also like it to be the case, however, that the user could, if they so desired, select text in the JSpinner's editor. This means that jSpinner.setEnabled(false) doesn't cut it.
    JSpinner does not support an "editable" property, and its editor already has a read-only JFormatted text field. What I need to do is disable any effect the spinner's buttons may have on its associated JFormattedTextField. What's the best way of doing this?
    Thanks,
    Laird

    not sure what you're trying to do - seems like you don't want to disable the
    spinner, just the buttons
    if so, this seems to work OK (1.4.0_01)
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Testing
      public void buildGUI()
        JPanel p = new JPanel();
        JSpinner spinner = new JSpinner(new SpinnerNumberModel(50, 0, 100, 5));
        spinner.setUI(new MyUI());
        p.add(spinner);
        JFrame f = new JFrame();
        f.getContentPane().add(p);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    class MyUI extends javax.swing.plaf.basic.BasicSpinnerUI
      protected Component createNextButton()
        return new javax.swing.plaf.basic.BasicArrowButton(SwingConstants.NORTH);
      protected Component createPreviousButton()
        return new javax.swing.plaf.basic.BasicArrowButton(SwingConstants.SOUTH);
    }

  • Help needed for jspinner

    Its the third time i am posting the same qusetion with out any sucess. Some one may knew the answer . Please help me
    I got a jspinner , a text box and a button in my frame. i valdiate the values entered in the text field and if an invalid value is entered an error dialog is show . Now if I enter an invalid value in the text field and click the buttons along with the jspinner, the error dialog is displayed and focus is returned back to the textbox,but the problem is that the spinner button remains in a pressed condition as a result the number keeps of increasing / decreasing in jspinner (if you click both the buttons , it will increase and decrease at the same time). I am including the code also.
    I have searched through the forums and couldnt find a solution. Is it a problem with jspinner or my code?
    thanks in advance
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class focus extends JFrame implements FocusListener {
    JPanel pan1=new JPanel();
    JButton btn1=new JButton("OK");
    JButton btn2=new JButton("Cancel");
    JTextField txt1=new JTextField(10);
    SpinnerCircularNumberModel model=new SpinnerCircularNumberModel(50);
    JSpinner spin=new JSpinner(model);
    focus() {
    getContentPane().setLayout(new FlowLayout());
    getContentPane().add(txt1);
    getContentPane().add(btn1);
    getContentPane().add(btn2);
    getContentPane().add(spin);
    txt1.addFocusListener(this);
    setSize(200,200);
    setVisible(true);
    pack();
    public void focusGained(FocusEvent fe) {
    public void focusLost(FocusEvent fe) {
    try {
    Integer.parseInt(txt1.getText());
    } catch ( NumberFormatException nfe) {
    JOptionPane.showMessageDialog(this, "Invalid value","ERROR", JOptionPane.ERROR_MESSAGE);
    txt1.requestFocus();
    public static void main(String arg[]) {
    focus f=new focus();
    class SpinnerCircularNumberModel extends SpinnerNumberModel {
    public SpinnerCircularNumberModel(int init) {
    super(init,0,99,1);
    public Object getNextValue() {
    int val = Integer.parseInt(getValue().toString());
    if(val==99)
    return (new Integer(0));
    else
    return (new Integer(++val));
    public Object getPreviousValue() {
    int val = Integer.parseInt(getValue().toString());
    if(val==0)
    return (new Integer(99));
    else
    return (new Integer(--val));

    i found out the answer . It was a bug with the jspinner.
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4840869

  • Using text in JSpinner SpinnerNumberModel.

    I was wondering if there is a way that I can use text in JSpinner SpinnerNumberModel.
    I have created a spinner as following:
    JSpinner spinner = new JSpinner(new SpinnerNumberModel(0,0,127,1));
    What I would like to do is put Text within the NumberModel so that when the spinner hits 127, it will display text such as "OFF"
    Is there a way I can implement this with a Spinner?
    Any help would be appreciated.
    Thanks.

    or you can paint a string, like this
    public void paint(Graphics g) {
         super.paint(g);
         g.drawString("Hello World!", x,y);  // replace x, y with your own coordinates
    }hope that helps

  • JSpinner and finding which item was selected...

    With a JComboBox, I can load up my list with an array and use "getSelectedIndex()" to grab the index number of the item the user selects.
    With a JSpinner (SpinnerListModel), I can load up my list with an array but there doesn't appear to be any way to retrieve an index number. Am I missing something? The best thing I can come up with is to use "getValue()" and search my array for that value and then I'd have the correct index. Seems the long way around to me.
    I have other elements in the array I need to get to based on the users selection.
    -Duane

    If you're creating your own object class to use in the list of possible values, you could make the array index be an instance variable in this class. I just had to do something like this recently. As in:
    class MySpinnerValue
      public int index;
      public String name;
      //  ... other useful stuff
      public String toString()
        return name;
    // ... and somewhere we create the list, like ...
    MySpinnerValue[] list=new MySpinnerValue[10];
    for (int x=0;x<10;++x)
      MySpinnerValue v=new MySpinnerValue();
      v.index=x;
      list[x]=v;
    }Then when you retrieve a value you just check index to see where it is in the array.
    Clumsy, yes, because it relies on setting an index value equal to the array subscript, which is redundant data in a sense. (Ah, there were advantages to pointers in C, you could just say "pEntry-entry[0]" to get the index ...)

  • Can't Set Value in JSpinner

    I am having trouble setting a value to a JSpinner in my code.
    I am using two JSpinners, both with SpinnerNumberModels.
    I use the Object JSpinner.getValue() method to get the current value from that JSpinner, change that object into an Integer format, and perform an arithmetic operation on the integer.
    I then change the resulting integer into an Object format, and call the method JSpinner.setValue(Object).
    The setValue method never changes the value of the JSpinner, and occasionally throws an IllegalArgumentException - depending on where I put it in the code.
    The problem appears to come from either all the changing formats or the setValue method.
    Any suggestions?

    Perhaps this example will help?
    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class Dork extends JFrame implements ActionListener
         JSpinner dizzy;
         public static void main(String[] args)
              Dork dork=new Dork();
         public Dork()
              super("Dork");
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              Container content=getContentPane();
              dizzy=new JSpinner(new SpinnerNumberModel(5,1,10,1));
              content.add(dizzy,BorderLayout.CENTER);
              JButton increment=new JButton("Increment");
              increment.addActionListener(this);
              content.add(increment,BorderLayout.SOUTH);
              pack();
              setLocationRelativeTo(null);
              show();
         public void actionPerformed(ActionEvent e)
              Integer value=(Integer)dizzy.getValue();
              Integer plusone=new Integer(value.intValue()+1);
              dizzy.setValue(plusone);
    }

  • JTable with JComboBox/JSpinner problem

    The following code has a JTable with 2 columns.The lst column has JComboBoxes, the 2nd column has JSpinners.I want to set the spinner range of values based on the selection of JComboBox. The JComboBox selections are "small" and "large". For "small" the spinner should range from 0..49, for "large" from 50..99. When a selection is made, MyTable.itemStateChanged() is called, which in turn calls SpinnerEditor.setValueRange(). This sets an array with the desired values and then sets the model with this array. However, it sets the range not only for the row in which the combo box was clicked, but all rows.
    So in MyTable.setCellComponents(), there is this:
    spinnerEditor = new SpinnerEditor(this, defaultTableModel);
    modelColumn.setCellEditor(spinnerEditor);
    If the table has n rows, are n SpinnerEditors created, or just 1?
    If 1, do n need to be created and if so, how?
    public class MyTable extends JTable implements ItemListener {
         private DefaultTableModel defaultTableModel;
         private Vector<Object> columnNameVector;
         private JComboBox jComboBox;
         private SpinnerEditor spinnerEditor;
         private final int COMBO_BOX_COLUMN = 0;
         final static int SPINNER_COLUMN = 1;
         public static String SMALL = "Small";
         public String LARGE = "Large";
         private final String[] SMALL_LARGE = {
                   SMALL,
                   LARGE };
         public MyTable(String name, Object[][] variableNameArray, Object[] columnNameArray) {
              columnNameVector = new Vector<Object>();
              // need column names in order to make copy of table model
              for (Object object : columnNameArray) {
                   columnNameVector.add(object);
              defaultTableModel = new DefaultTableModel(variableNameArray, columnNameArray);
              this.setModel(defaultTableModel)     ;
              setCellComponents();
              setListeners();
         private void setCellComponents() {
              // combo box column -----------------------------------------------
              TableColumn modelColumn = this.getColumnModel().getColumn(COMBO_BOX_COLUMN);
              jComboBox = new JComboBox(SMALL_LARGE);
              // set default values
              for (int row = 0; row < defaultTableModel.getRowCount(); row++) {
                   defaultTableModel.setValueAt(SMALL_LARGE[0], row, COMBO_BOX_COLUMN);
              modelColumn.setCellEditor(new DefaultCellEditor(jComboBox));
              DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
              renderer.setToolTipText("Click for small/large"); // tooltip
              modelColumn.setCellRenderer(renderer);
              // index spinner column ------------------------------------------------------------
              modelColumn = this.getColumnModel().getColumn(SPINNER_COLUMN);
              spinnerEditor = new SpinnerEditor(this, defaultTableModel);
              modelColumn.setCellEditor(spinnerEditor);
              renderer = new DefaultTableCellRenderer();
              renderer.setToolTipText("Click for index value"); // tooltip
              modelColumn.setCellRenderer(renderer);
         private void setListeners() {
              jComboBox.addItemListener(this);
         @Override
         public void itemStateChanged(ItemEvent event) {
              // set spinner values depending on small or large
              String smallOrLarge = (String)event.getItem();
              if (this.getEditingRow() != -1 && this.getEditingColumn() != -1) {
                   spinnerEditor.setValueRange(smallOrLarge);
         public static void main(String[] args) {
              try{
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              catch (Exception e){
                   e.printStackTrace();
              String[] columnNameArray = {"JComboBox", "JSpinner"};
              Object[][]  dataArray = {
                        {"", "0"},
                        {"", "0"},
                        {"", "0"},
              final MyTable myTable = new MyTable("called from main", dataArray, columnNameArray);
              final JFrame frame = new JFrame();
              frame.getContentPane().add(new JScrollPane(myTable));
              frame.setTitle("My Table");
              frame.setPreferredSize(new Dimension(200, 125));
              frame.addWindowListener(new WindowAdapter(){
                   @Override
                   public void windowClosing(WindowEvent e) {
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setLocation(800, 400);
              frame.pack();
              frame.setVisible(true);
    public class SpinnerEditor extends AbstractCellEditor implements TableCellEditor {
         private JComponent parent;
         private DefaultTableModel defaultTableModel;
         private final JSpinner spinner = new JSpinner();
         private String[] spinValues;
         private int row;
         private int column;
         public SpinnerEditor(JTable parent, DefaultTableModel defaultTableModel ) {
              super();
              this.parent = parent;
              this.defaultTableModel = defaultTableModel;
              setValueRange(MyTable.SMALL);
              // update every time spinner is incremented or decremented
              spinner.addChangeListener(new ChangeListener(){
                   public void stateChanged(ChangeEvent e) {
                        String value = (String) spinner.getValue();
                        System.out.println ("SpinnerEditor.stateChanged(): " + value);
                        setValue(value);
         private void setValue(String value) {
              // save to equation string
              System.out.println ("SpinnerEditor.setValue(): " + value + " at (" + row + ", " + MyTable.SPINNER_COLUMN + ")");
              ((JTable) parent).setValueAt(spinner.getValue(), this.row, this.column);
         @Override
         public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)      {
              System.out.println ("SpinnerEditor.getTableCellEditorComponent(): row: " + row + "\tcolumn: " + column);
              System.out.println ("SpinnerEditor.getTableCellEditorComponent(): value: " + value);
              this.row = row;
              this.column = column;
              return spinner;
         @Override
         public boolean isCellEditable(EventObject evt) {
              return true;
         // Returns the spinners current value.
         @Override
         public Object getCellEditorValue() {
              return spinner.getValue();
         @Override
         public boolean stopCellEditing() {
              System.out.println("SpinnerEditor.stopCellEditing(): spinner: " + spinner.getValue() + " at (" + this.row + ", " + this.column + ")");
              ((JTable) parent).setValueAt(spinner.getValue(), this.row, this.column);
              return true;
         public void setValueRange(String smallOrLarge) {
              System.out.println ("SpinnerEditor.setValueRange for " + smallOrLarge);
              final int ARRAY_SIZE = 50;
              if (MyTable.SMALL.equals(smallOrLarge)) {
                   final int MIN_SPIN_VALUE = 0;               
                   final int MAX_SPIN_VALUE = 49;
                   //System.out.println ("SpinnerEditor.setValueRange(): [" + MIN_SPIN_VALUE + ".." +  MAX_SPIN_VALUE + "]");
                   spinValues = new String[ARRAY_SIZE];
                   for (int i = MIN_SPIN_VALUE; i <= MAX_SPIN_VALUE; i++) {
                        spinValues[i] = new String(Integer.toString(i));
              else { // large
                   final int MIN_SPIN_VALUE = 50;               
                   final int MAX_SPIN_VALUE = 99;
                   //System.out.println ("SpinnerEditor.setValueRange(): [" + MIN_SPIN_VALUE + ".." +  MAX_SPIN_VALUE + "]");
                   spinValues = new String[ARRAY_SIZE];
                   for (int i = 0; i <ARRAY_SIZE; i++) {
                        spinValues[i] = new String(Integer.toString(MIN_SPIN_VALUE + i));
                   //for (int i = 0; i <ARRAY_SIZE; i++) {
                   //     System.out.println ("spinValues[" + i + "] = " + spinValues);
              System.out.println ("SpinnerEditor.setValueRange(): [" + spinValues[0] + ".." + spinValues[ARRAY_SIZE-1] + "]");
              // set model
              spinner.setModel(new SpinnerListModel(java.util.Arrays.asList(spinValues)));

    However, it sets the range not only for the row in which the combo box was clicked, but all rows. Yes, because a single editor is used by the column.
    One solution is to create two editors, then you override the getCellEditor(...) method to return the appropriated editor. Something like:
    If (column == ?)
        if (smallOrLarge)
          return the small or large spinner editor
        else
           return the large spinner editor
    else
        return super.getCellEditor(...);

  • How do I get the active field of DateEditor in JSpinner?

    Hi Everybody,
    I have a JSpinner which uses a DateEditor and displayes the date in "dd/MM/yyyy" format in it. I have over ridden the default behaviour of Up and Down arrow button components of it as per my requirements. Now I want to extend the functionality to change the value of the date on the basis of what is the highlighted field.
    ie if the month is highlighted then the day and year need to
    remain the same but month should increase.and if day is higlited it
    shud follow the normal pattern and if year is highlighted the year should
    move forward keeping the month and date same (no doubt after 12 months increment it is supposed to go to next year). Here is my code:
    <code>
    bq. import java.awt.BorderLayout; \\ import java.awt.Component; \\ import java.awt.event.KeyEvent; \\ import java.awt.event.KeyListener; \\ import java.awt.event.MouseAdapter; \\ import java.awt.event.MouseEvent; \\ import java.awt.event.MouseListener; \\ import java.text.SimpleDateFormat; \\ import java.util.Calendar; \\ import java.util.Date; \\ import java.util.GregorianCalendar; \\ import java.util.StringTokenizer; \\ import javax.swing.JFrame; \\ import javax.swing.JPanel; \\ import javax.swing.JSpinner; \\ import javax.swing.SpinnerDateModel; \\ import javax.swing.SpinnerModel; \\ /** \\ * \\ */ \\ /** \\ * @author asmarwal \\ * \\ */ \\ public class MySpinnerDemo extends JPanel implements MouseListener { \\ static JPanel myPanel; \\ static int day = 0; \\ static int month = 0; \\ static int year = 0; \\ static String date; \\ static JSpinner.DateEditor de = null; \\ static Calendar calendar = Calendar.getInstance(); \\ public MySpinnerDemo(){ \\ // Let's see it later if we need to do sth here \\ myPanel = new JPanel(new BorderLayout()); \\ } \\ private static JSpinner getSpinner(){ \\ // initDate, earliestDate & latestDate might be taken from constructor too \\ Date nowDate = calendar.getTime(); \\ calendar.add(Calendar.YEAR, 0); \\ Date earliestDate = calendar.getTime(); \\ Calendar latestCal = new GregorianCalendar(9999, Calendar.DECEMBER, 31); \\ Date latestDate = latestCal.getTime(); \\ System.out.println("InitDate:: "+nowDate+"\n Earliest Date:: "+earliestDate+"\n Latest Date:: "+latestDate); \\ SpinnerModel dateModel = new SpinnerDateModel(nowDate, \\ earliestDate, \\ latestDate, \\ Calendar.YEAR);//ignored for user input \\ JSpinner spinner = new JSpinner(dateModel); \\ Calendar currCal = new GregorianCalendar(); \\ spinner.setValue(currCal.getTime()); \\ spinner.setEditor(new JSpinner.DateEditor(spinner, "dd/MM/yyyy")); \\ spinner.setUI(new javax.swing.plaf.basic.BasicSpinnerUI() { \\ protected Component createNextButton() { \\ Component u = super.createNextButton(); \\ u.addMouseListener(new MouseAdapter() { \\ public void mouseClicked(MouseEvent me){ \\ System.out.println("You have just clicked the up arrow button of UI component..."); \\ calendar.add(Calendar.DATE, 1); \\ spinner.setValue(calendar.getTime()); \\ myPanel.repaint(); \\ } \\ }); \\ return u; \\ } \\ //Down Arrow button \\ protected Component createPreviousButton() { \\ Component u = super.createNextButton(); \\ u.addMouseListener(new MouseAdapter() { \\ public void mouseClicked(MouseEvent me){ \\ System.out.println("You have just clicked the down arrow button of UI component... ActiveField:: "); \\ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); \\ Calendar calToday = new GregorianCalendar(); \\ String calTodaDateStr = sdf.format(calToday.getTime()); \\ String spinnerCurrDateStr = sdf.format(calendar.getTime()); \\ //Checking if spinner's current date value is today's.. \\ // If yes then go to 31/12/9999 else perform normal date decrement \\ if(spinnerCurrDateStr.equalsIgnoreCase(calTodaDateStr)){ \\ System.out.println("IF:: spinnerCurrDateStr: "+spinnerCurrDateStr+" calTodaDateStr"+calTodaDateStr); \\ Calendar newCal = new GregorianCalendar(9999, Calendar.DECEMBER, 31); \\ //    Set the static var calendar's value to the current system date \\ calendar = new GregorianCalendar(); \\ spinner.setValue(newCal.getTime()); \\ }else{ \\ System.out.println("ELSE:: spinnerCurrDateStr: "+spinnerCurrDateStr+" calTodaDateStr"+calTodaDateStr); \\ calendar.add(Calendar.DAY_OF_MONTH, (-1)); \\ spinner.setValue(calendar.getTime()); \\ } \\ myPanel.repaint(); \\ } \\ public void mousePressed(MouseEvent me){ \\ System.out.println("You have just kept pressed the down arrow button of UI component..."); \\ // Don't do anything \\ calendar.add(Calendar.DAY_OF_MONTH, 0); \\ spinner.setValue(calendar.getTime()); \\ myPanel.repaint(); \\ } \\ }); \\ return u; \\ } \\ }); \\ return spinner; \\ } \\ public void mouseClicked(MouseEvent e) { \\ // TODO Auto-generated method stub \\ } \\ public void mouseEntered(MouseEvent e) { \\ // TODO Auto-generated method stub \\ } \\ public void mouseExited(MouseEvent e) { \\ // TODO Auto-generated method stub \\ } \\ public void mousePressed(MouseEvent e) { \\ // TODO Auto-generated method stub \\ } \\ public void mouseReleased(MouseEvent e) { \\ // TODO Auto-generated method stub \\ } \\ /** \\ * @param args \\ */ \\ public static void main(String[] args) { \\ // TODO Auto-generated method stub \\ JFrame frame = new JFrame("JSpinner Sample"); \\ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); \\ MySpinnerDemo msd = new MySpinnerDemo(); \\ //System.out.println("msd.getSpinner():: "+msd.getSpinner()); \\ myPanel.add(getSpinner(), BorderLayout.CENTER); \\ frame.getContentPane().add(myPanel, BorderLayout.SOUTH); \\ frame.setSize(200, 90); \\ frame.setVisible(true); \\ } \\ }
    </code>
    Thanks in advance!

    Simmi,
        you need to check in SE11(data dictionary) with the specified tachnical names.
    comming to selective deletion...
    divide the data into segments based on the organizational values.
    take the material group. check with any consultant. ask simple qustion how many material group we have?
    take the case 5 mat1, mat2, mat3, mat4, mat5. Delete the values based on that. Menas that... entire infocube defined into 5 segments.
    Before deleting make sure u have taken correct charecterstic. if you can give us the scenario we can let you know how can we delete the data with out effecting existing business process.
    alll the best.
    Regards,
    Nagesh Ganisetti.

  • Using a JSpinner in JBuilder

    I am new to using JBuilder and I am trying to use a JSpinner in my application but I am unable to compile and I get this message:
    "Frame1.java": Error #: 300 : class JSpinner not found in class testing.Frame1 at line 41, column 3
    I am using JBuilder 6 with java virtual machine java.vm.version 1.3.1-b24 and I am have the following import statements:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.*;
    import javax.swing.table.AbstractTableModel;
    import java.util.Hashtable;
    import javax.swing.JScrollPane;
    Is there any way for me to use a JSpinner with this version of JBuilder or any advice, please help. Thanks.

    HI... Try JBuilder 8 & jdk 1.4.1. Im not sure but i think that the JSpinner wasnt implemented all the way in jdk's past 1.4

  • JSpinner in JTable: commit edit

    Hi all,
    I have a JSpinner in a JTable, with corresponding renderer and editor.
    All works good, but now I want that when the user changes the value of the spinner this change is immediately committed (and not only when the user goes to another cell in the table)
    Any suggestions? Thx a lot

    To get better help sooner, post a SSCCE that clearly demonstrates your problem.
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    db

  • JSpinner problem when extending AbstractSpinnerModel

    Hi,
    I have a problem with a class that extends AbstractSpinnerModel.
    My class is
      class MaxSpinnerModel extends AbstractSpinnerModel {
        Double value;
        public Object getNextValue() {
          // deltaSP is a JSpinner from wich I want to get the value (see rules below)
          value = new Double(value.doubleValue() + ((Double)deltaSP.getValue()).doubleValue());
          return value;
        public Object getPreviousValue() {
          // deltaSP is a JSpinner from wich I want to get the value (see rules below)
          value = new Double(value.doubleValue() - ((Double)deltaSP.getValue()).doubleValue());
          return value;
        public Object getValue() {
          if (value == null) {
            value = new Double(MAX_INI);
          return value;
        public void setValue(Object value) {
          if ((value == null) || !(value instanceof Double)) {
            throw new IllegalArgumentException("illegal value");
          if (!value.equals(this.value)) {
            this.value = (Double)value;
            fireStateChanged();
      }I have two problems:
    -1 the editor is not editable ( when trying to put an Editor like a JFormattedTextField,
    values are not visible)
    -2 the most important so far, pressing the up or down button of the JSpinner do not
    change the value on the screen while the method getNext or PreviousValue are
    called.
    What should I do to fix these two bugs?
    I need to implement my spinner model because I would like to
    bind dynamically the increment and decrement of the different spinner.
    I must have the following rules for next and previous values:
    -1 min
    increment/decrement of min is delta and incrmenting min, should mofiy
    middle (middle = min+max/2), and delta (delta = max -min), mas does not
    change
    -2 max same as min
    -3 delta quit complicated let's say, increment/decrement is *2.0 and *0.5,
    middle does not change, min and max change with the rules
    min = middle - delta/2, max = middle + delta/2
    -4 middle increment/decrement is delta, min and max are simply shited of delta

    Hello,
    I managed to solve the second question on my own.
    I created another InfoSource and another Update rule to the InfoObject with flexible updating. It doesn’t erase the old data anymore.
    Although I still have problems with the time characteristics.
    Thank you,
    Best regards

  • JSPinner in a JTable Cell

    Plz let me know how to add a JSpinner component in a JTable cell.I was able to add JCOmbo and Jtextfield,,but i need to add a JSpinner...how to do that...
    regds
    Subhash.K

    thank you for responce
    Object[][] data1 = {
                              {"Datum", new Spinner(new SpinnerNumberModel(200,1,255,1)),""}, //this sets the innitial value to 200
                             {"ActiveAntenna", new Boolean(true),""}
    String[] colname1 = {"Variable","Value","Unit"};do you have an idea how to set the value, min, and step in my Spinner class
    regards
    gebi

Maybe you are looking for

  • Where is the "month" view on the calendar in iOS7?

    The subject is my question. What happened to the month view on the calendar in iOS7? I really liked my MONTH view. Mine is showing only 3 options: Today, Calendars, Inbox. I really liked being able to see what is scheduled for the month.  Now I have

  • Incredibly Frustrated w iPhoto (simple copying)

    Since 2005, I have nearly 35,000 images and video footage that I would like to COPY onto an[other] external drive. When I started filling up my iMac, I purchased an external drive for Time Machine purposes, and also created a folder that iPhoto would

  • Problem with FOR ALL ENTRIES IN

    This is my simple source code. TABLES: stpo. DATA:  t_stpo      LIKE  stpo  OCCURS 0 WITH HEADER LINE, t_stpo_itm      LIKE  stpo  OCCURS 0 WITH HEADER LINE, t_stpo-stlnr = '00000058'. t_stpo-stlkn = '00000003'. append t_stpo. t_stpo-stlnr = '0000005

  • Want to create multiuser example

    Hi, I want to create a application in which same vi will run on 3 or 4 computers connected on LAN.Its like a multiplayer game. Is it possible? Are there any examples of such application. can someone give me such application to design. Thank you  Gaur

  • AU and VST third-party plugs not showing up

    This is in the Mac CS5.5 official released version.  They did show up and worked fine in Audition Mac Beta. Specifically, I have PSP Vintage Warmer, and WaveArts Masterverb and Track Plug.  They do show up and work in MOTU Digital Performer, Final Cu