JSpinner and KeyListener

Hi...
I have a problem with the JSpinner... How I can add a KeyEvent???
I try this way, but it don't work:        ((JSpinner.DefaultEditor)spn_Cantidad.getEditor()).getTextField().addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent e){
                JOptionPane.showMessageDialog(null,e.getSource().toString());
        });Please help... I try different ways... but don't work...
Regards...

I try to run the code in a sample, and it's work fine... no problems...
But when I try to put it in my application, it don't work... and I don't know why...
My code is very long... up to 2300 lines... but it's not generated by NetBeans...
The code where I have the problem is this:import java.util.*;
import java.util.Date;
import java.text.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
import javax.swing.text.*;
    public class Bar_Main extends JDialog implements ActionListener, KeyListener{
    JPanel Panel_Main;
    JLabel lbl_Fecha;
    JLabel lbl_Fecha_Actual;
    JLabel lbl_Producto;;
    JLabel lbl_Cantidad;
    JLabel lbl_Precio;
    JLabel lbl_Total;
    JComboBox cmb_Prod_Nom, cmb_Prod_Cod;
    JSpinner spn_Cantidad;
    JTextField txt_Precio;
    JTextField txt_Total;
    //javax.swing.Timer tmr_Reloj;
    java.util.Date Fecha;
    DateFormat frmt_Fecha;
    //SimpleDateFormat frmt_Hora;
    Connection conec;
    Statement state;
    ResultSet rec;
    public Bar_Main(){
        setTitle("Consumo de Bar");
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            conec = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/POOL/Data/BaseDat.MDB");
            state = conec.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
        }catch(Exception e){}
        frmt_Fecha = DateFormat.getDateInstance(DateFormat.FULL);
        Fecha = new java.util.Date();
        Panel_Main = new JPanel(null);
        Panel_Main.setBackground(Color.GREEN.darker());              
        lbl_Fecha = new JLabel("Fecha");
        lbl_Fecha.setBounds(20,20,80,20);
        lbl_Fecha_Actual = new JLabel(frmt_Fecha.format(Fecha).toUpperCase());
        lbl_Fecha_Actual.setBounds(130,20,230,20);
        lbl_Producto = new JLabel("Elija Producto");
        lbl_Producto.setBounds(20,50,80,20);
        cmb_Prod_Nom = new JComboBox(Cargar_Combo_Nom());
        cmb_Prod_Nom.setBounds(130,50,230,20);
        cmb_Prod_Nom.addActionListener(this);
        cmb_Prod_Cod = new JComboBox(Cargar_Combo_Cod());
        lbl_Cantidad = new JLabel("Cantidad");
        lbl_Cantidad.setBounds(20,80,80,20);
        spn_Cantidad = new JSpinner();
        spn_Cantidad.setBounds(130,80,50,20);
                ((JSpinner.DefaultEditor)spn_Cantidad.getEditor()).getTextField().addKeyListener(new KeyAdapter() {
            public void keyTyped(KeyEvent e){
                JOptionPane.showMessageDialog(null,e.getKeyChar());
        lbl_Precio = new JLabel("Valor Unitario");
        lbl_Precio.setBounds(20,110,80,20);
        txt_Precio = new JTextField("");
        txt_Precio.setBounds(130,110,50,20);
        txt_Precio.setHorizontalAlignment(JTextField.RIGHT);
        txt_Precio.setEnabled(false);
        txt_Precio.setDisabledTextColor(Color.DARK_GRAY);
        try{
            rec = state.executeQuery("Select * from Productos where prod_id = " + cmb_Prod_Cod.getSelectedItem());
            rec.absolute(1);
            spn_Cantidad.setModel(new SpinnerNumberModel(1,1,rec.getInt("prod_cant"),1));
            txt_Precio.setText(Integer.toString(rec.getInt("prod_precio")));
        }catch(Exception e){JOptionPane.showMessageDialog(null,e.getMessage());}
        Panel_Main.add(lbl_Fecha); Panel_Main.add(lbl_Fecha_Actual);
        Panel_Main.add(lbl_Producto); Panel_Main.add(cmb_Prod_Nom);
        Panel_Main.add(lbl_Cantidad); Panel_Main.add(spn_Cantidad);
        Panel_Main.add(lbl_Precio); Panel_Main.add(txt_Precio);
        setLayout(new BorderLayout());
        add(Panel_Main,BorderLayout.CENTER);
        setSize(600,400);
        setLocationRelativeTo(null);
        setModal(true);
        setVisible(true);
    public DefaultComboBoxModel Cargar_Combo_Nom(){
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        try{           
            rec = state.executeQuery("Select * from Productos where prod_cant > 0 order by prod_nom");
            rec.first();
            while(rec.isAfterLast() == false){
                model.addElement(rec.getString("prod_nom"));
                rec.next();
        }catch(Exception e){}
        return model;
    public DefaultComboBoxModel Cargar_Combo_Cod(){
        DefaultComboBoxModel model = new DefaultComboBoxModel();
        try{
            rec = state.executeQuery("Select * from Productos where prod_cant > 0 order by prod_nom");
            rec.first();
            while(rec.isAfterLast() == false){
                model.addElement(rec.getString("prod_id"));
                rec.next();
        }catch(Exception e){}
        return model;
    public void actionPerformed(ActionEvent ae) {
        if (ae.getSource().equals(cmb_Prod_Nom)){
            cmb_Prod_Cod.setSelectedIndex(cmb_Prod_Nom.getSelectedIndex());
            try{
                rec = state.executeQuery("Select * from Productos where prod_id = " + cmb_Prod_Cod.getSelectedItem());
                rec.absolute(1);
                spn_Cantidad.setModel(new SpinnerNumberModel(1,1,rec.getInt("prod_cant"),1));
                txt_Precio.setText(Integer.toString(rec.getInt("prod_precio")));
            }catch(Exception e){}
    public void keyPressed(KeyEvent e) {
    public void keyReleased(KeyEvent e) {
    public void keyTyped(KeyEvent e) {
}Please help me...
Regards...

Similar Messages

  • JDK1.4 JSPinner and DateFormatSymbols

    Hi,
    I have a problem with DateFormatSymbols().getWeekdays(); use in JSPinner and JCOmboBox
    The getWeekdays() method returns a STring[] containing the nameof the days (sunday, ...) in a localized way. I want to use these names inside a JSPinner or a JCombobox. The names are properly inserted, but there is a 'empty' value containing no string, even after calling the setEditable(false)
    any idea on how to remove that empty 'day'??
    thanks,
    vincent

    Store the String[] in a local copy and remove from that local copy manually the "empty day". Then use the manipulated local copy in the JComboBox ...

  • JSpinner and very small values

    I Have a JSpinner and i wrote this code
    Double v = new Double(3.111110001111111111111111111111111111111111111);
    double min = 0;
    double max = 10;
    double step = 0.0001;
    SpinnerModel spinnerModel = new SpinnerNumberModel(v.doubleValue(),min,max,step);The are two problems
    1. The variable v is represented as '3,111'
    2. The step is incorrect... When i click on the up arrow, the number don't change. If I set the step to '0.001' all works correctly.
    There is a solution?

    If step = 0.0001 or step < 0.0001, the increment andthe decrement don't work
    correctly. The number displayed in the JSpinnerdon't change.
    If step = 0.001 all works correctly.
    Why if step = 0,001 it works, and if step = 0.0001it don't works correctly?
    It probly does work correctly, its just you are
    incrementing the 4th decimal place and the spinner
    only shows 3 decimal places.
    So you ARE incrementing, you just wont see it until
    after you increment 10 times and the 3rd decimal
    rounds up.If I increment 10 times the 4th decimal value, the 3rd decimal value don't change.
    Anyone can solve this problem?

  • MaskFormatter with JSpinner and DateEditor?

    Hi,
    I'm trying to apply a MaskFormatter to the DateEditor on a JSpinner. We want the ability to both manually edit the fields by hand AND/OR click the up/down arrows.
    The one gotcha is that when manually entering the values, we want to set a mask on the field so the user doesn't have to type in the ":" when separating the time fields. Right now, when they can delete all the text in the spinner textfield.
    I've dug through the source code of JSpinner and it appears that I should be able to get the editors JFormattedTextField and set the MaskFormatter as part of the AbstractFormatFactory. But all I end up with is a blank JSpinner and I can't type in the textfield.
    Below is my code:
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.util.Calendar;
    import java.util.Date;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSpinner;
    import javax.swing.SpinnerDateModel;
    import javax.swing.SpinnerModel;
    import javax.swing.text.DefaultFormatterFactory;
    import javax.swing.text.MaskFormatter;
    public class MaskedFieldTest {
         public static void main(String[] args) {
              final JFrame f = new JFrame("Textfield demo");
              f.setDefaultCloseOperation(f.DISPOSE_ON_CLOSE);
              f.addWindowListener(new WindowAdapter() {
                   public void windowClosed(WindowEvent e) {
                        System.exit(0);
              f.setSize(250, 70);
              try {
                   // Create a spinner
                   JSpinner spinner = new JSpinner();
                   // Set up a dummy calendar for the model
                   Calendar calendar = Calendar.getInstance();
                   Date initDate = calendar.getTime();
                   calendar.add(Calendar.YEAR, -100);
                   Date earliestDate = calendar.getTime();
                   calendar.add(Calendar.YEAR, 200);
                   Date latestDate = calendar.getTime();
                   // Set the model
                   SpinnerModel dateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);
                   spinner.setModel(dateModel);
                   // Create the dateeditor using the time format we want displayed in the spinner
                   JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(spinner, "hh:mm:ss a");
                   // Create a mask for editing so we don't have to manually add the :
                   MaskFormatter fmt = new MaskFormatter("##:##:## UU");
                   // Get the factory from the editor and set the maskformatter for the editing portion
                   DefaultFormatterFactory form = (DefaultFormatterFactory)dateEditor.getTextField().getFormatterFactory();
                   form.setEditFormatter(fmt);
                   // Finally, assign the editor to the spinner
                   spinner.setEditor(dateEditor);
                   // Display the panel
                   JPanel panel = new JPanel();
                   panel.add(spinner);
                   f.getContentPane().add(panel);
                   f.setVisible(true);
              } catch (java.text.ParseException e) {
                   e.printStackTrace();
    }If you run the code, you'll just get an empty JSpinner and you can't do anything in the textfield even though it is enabled.
    I'm running JDK.1.4.2_09 on Windows XP SP2
    Has anyone used a MaskFormatter with a DateEditor on a JSpinner before?
    Thanks,
    - Tim

    see weebib's post here
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=581804

  • Colors of JSpinner and JComboBox

    hello
    I like to change the fore- and backgroundcolors of JSpinner and JComboBox. how can I do this?
    thanks in advance! nix

    this is much easyer code I will use it.
    but the button is anyway gray and black!?You want to change the color of the arrowButton and arrow color?
    there's probably an easier way, but this worked OK for me
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.plaf.basic.BasicSpinnerUI;
    import javax.swing.plaf.basic.BasicArrowButton;
    class Testing extends JFrame
      public Testing()
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocation(400,300);
        JSpinner spinner = new JSpinner(new SpinnerNumberModel(50, 0, 100, 5));
        spinner.setUI(new MyUI());
        ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField().setBackground(Color.GREEN);
        JPanel jp = new JPanel();
        jp.add(spinner);
        getContentPane().add(jp);
        pack();
      public static void main(String[] args) {new Testing().setVisible(true);}
    class MyUI extends BasicSpinnerUI
      protected Component createNextButton()
        JButton btn = (JButton)super.createNextButton();
        JButton btnNext = new MyBasicArrowButton(SwingConstants.NORTH);
        btnNext.addActionListener(btn.getActionListeners()[0]);
        btnNext.setBackground(Color.BLACK);
        return btnNext;
      protected Component createPreviousButton()
        JButton btn = (JButton)super.createPreviousButton();
        JButton btnPrevious = new MyBasicArrowButton(SwingConstants.SOUTH);
        btnPrevious.addActionListener(btn.getActionListeners()[0]);
        btnPrevious.setBackground(Color.BLACK);
        return btnPrevious;
    class MyBasicArrowButton extends BasicArrowButton
      public MyBasicArrowButton(int direction)
        super(direction);
      public MyBasicArrowButton(int direction,Color background,Color shadow,Color darkShadow,Color highlight)
        super(direction,background,shadow,darkShadow,highlight);
      public void paintTriangle(Graphics g,int x,int y,int size,int direction,boolean isEnabled)
        Color oldColor = g.getColor();//Note 1: all if(!isEnabled) code removed, for brevity
        int mid, i, j;                //Note 2: all EAST / WEST code removed, for brevity
        j = 0;
        size = Math.max(size, 2);
        mid = (size / 2) - 1;
        g.translate(x, y);
        g.setColor(Color.GREEN);//<-------------------set arrow colors here
        switch(direction)
          case NORTH:
            for(i = 0; i < size; i++)
              g.drawLine(mid-i, i, mid+i, i);
            break;
          case SOUTH:
            j = 0;
            for(i = size-1; i >= 0; i--)
              g.drawLine(mid-i, j, mid+i, j);
              j++;
            break;
        g.translate(-x, -y);
        g.setColor(oldColor);
    }

  • 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 ...)

  • JTextField and keyListener

    I'm trying to create an easy way of inputting data in a JTextField. I have a column of textfields, each requiring fixed-length data-input, and the idea is that the user types series of two digits continuously, without having to press ENTER or TAB between them to go to the next textfield. For this I have created a keyListener, in which the length of the textfield is checked. Strangely enough, the length of the textfield always seems to be lagging one character. For instance, I have entered a "1" (which de keyListener registers without fail), but when I check the length of the textfield in the keyListener, it returns 0, and if you do a system-output of the textfield getText, you get an empty string. If I next enter a "2", the length of the textfield is 1 according to the listener, the system-output shows "1", and so on. I am doing anything wrong?

    Well, my point was to post the code that you tested. People make stupid mistakes like using:
    public void KeyReleased(KeyEvent e)
    Note: the capital "K". If you don't post the code you use then we can't help. Myself and others do not have a problem using the keyReleased() method.
    Here's is some working code. It enables/disables some buttons based on whether text is entered in the "Find" text field:
    http://www.discoverteenergy.com/files/FindReplace.java

  • JSplitPane Active Side and KeyListener

    I have a JSplitPane as my root in a JFrame. The left side is a JTabbedPane and the right is a custom JPanel. The JPanel has its own KeyListener implemented; however key strokes are going to the left JTabbedPane. If i switch the two sides, putting the custom JPanel on the left, the keystrokes work as desired. This is not the most desirable fix though. Does anyone know how to change the "active" side of the JSplitPane?

    The JPanel has its own KeyListener implemented; however key strokes are going to the left JTabbedPane.I find this hard to believe. I'm guessing your have a programming bug and since you didn't post any code I don't know how we can help you.
    Post your [url http://www.physci.org/codes/sscce.jsp]Simple Executable Demo Code so we can see this unwanted behaviour.

  • JSPinner and floating point quirk

    Please test these spinners only with their down arrow buttons to reach minimum value of each. When the number of fraction columns are 5,10 and 12, spinner stops at one step before the real minimum. They don't go to the real minimum. Why could this happen?
    import javax.swing.*;
    import java.text.*;
    public class SpinnerQuirk{
      public static void main(String[] args){
        Box panel = new Box(BoxLayout.X_AXIS);
        double fraction = 0.01;
        double base = 1.0;
        String fmt = "#0.00";
        for (int i = 2; i < 14; ++i){
          DecimalFormat df = new DecimalFormat(fmt);
          Box box = new Box(BoxLayout.Y_AXIS);
          JSpinner spinner = new JSpinner();
          SpinnerNumberModel spinnerModel
            = new SpinnerNumberModel(base + fraction,
                                     base + fraction - fraction * 101,
                                     base + fraction + fraction * 99,
                                     fraction);
          spinner.setModel(spinnerModel);
          spinner.setEditor(new JSpinner.NumberEditor(spinner, fmt));
          JLabel label = new JLabel("min = "
              + df.format((base + fraction - fraction * 101)));
          box.add(spinner);
          box.add(label);
          panel.add(box);
          fraction = fraction / 10.0;
          fmt += "0";
        JOptionPane.showMessageDialog(null, panel);
        System.exit(0);
    }

    Thanks. I think I have found the root cause of the problem. That is, there's no effective communications between java.text formatting and javax.swing.text one(*). A bad example of a bureaucratic sectionalism at Sun?
    (*: Because DecimalFormat does the right job given the same format string and same value.)
    Japanese: tate wari
    Englisn: divided vertically
    Edited by: hiwa on Oct 5, 2007 11:18 AM

  • Issues with ActionListener and KeyListener, what am i doing wrong?

    basically the program will complie, but not run properly, in appletviewer or a browser. The code for the buttons will be added later, but the test code seems to be working ok. The code for KeyListener does not move the square in the applet as it should, and when i close the applet it will dump a long error message to the dos window. if i comment out Action listener then KeyListener will work fine. if i comment out KeyListener then the applet will close with no error message to the dos window.
    i'm new to java and i don't know if i am doing anything wrong. please help, thankyou.
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    public class Project22 extends Applet implements KeyListener, ActionListener {
    private int score = 0;
    private int speed = 5;
    private int [] frame = {500, 500};
    private int [] sqr_loc = {235, 235};
    private char keyinput;
    private Button new_b = new Button("New Ball");
    private Button ext_app = new Button("Exit");
    private int junk = 0; // debug
    private Label message = new Label("start"); // debug
    public void actionPerformed(ActionEvent event) {
    Object source = event.getSource();
    if(source == new_b) {    // not coded yet
    ++junk;
    message.setText(Integer.toString(junk));
    else if(source == ext_app) {     // not coded yet
    ++junk;
    message.setText(Integer.toString(junk));
    public void keyTyped(KeyEvent event) {}
    public void keyPressed(KeyEvent event) {
         int keycode = event.getKeyCode();
    if(keycode == KeyEvent.VK_RIGHT) {
    if(sqr_loc[0] < 475) {
    sqr_loc[0] += speed;
    repaint();
    else if(keycode == KeyEvent.VK_LEFT) {
    if(sqr_loc[0] > 0) {
    sqr_loc[0] -= speed;
    repaint();
    else if(keycode == KeyEvent.VK_UP) {
    if(sqr_loc[1] > 0) {
    sqr_loc[1] -= speed;
    repaint();
    else if(keycode == KeyEvent.VK_DOWN) {
    if(sqr_loc[1] < 475) {
    sqr_loc[1] += speed;
    repaint();
    public void keyReleased(KeyEvent event) {}
    public void paint(Graphics g) {
    g.drawRect(sqr_loc[0], sqr_loc[1], 25, 25);
    }     // end paint
    public void init() {
    add(new_b);
    add(ext_app);
    add(message);
    new_b.addActionListener(this);
    ext_app.addActionListener(this);
    addKeyListener(this);
    requestFocus();
    }     // end Project22

    Perhaps the error message can help to determine the problem?

  • Thread and KeyListener

    I create a class which extends JFrame named as ShowFrame
    Another class which extends JPanel nameds as IncludePanel
    these two classes are stored in two different files named as ShowFrame.java and IncludePanel.java
    here is the code
    public class ShowFrame extends JFrame implements KeyListener,ActionListener
    IncludePanel CenterPanel;
    public ShowFrame()
    CenterPanel=new IncludePanel();
    this.addKeyListener(this);
    ........................//codes for adding buttons like start
    Container contentpane=getContentPane();
    JPanel EastPanel= new JPanel();
         JPanel WestPanel= new JPanel();
              JPanel NorthPanel= new JPanel();
              JPanel SouthPanel= new JPanel();
    .........................//add all created panels into the ContentPane
    start.addActionListener(
    new ActionListener() {
    public void actionPerformed( ActionEvent e )
                        start.setEnabled(false);
    CenterPanel.drawCircle();
    public class IncludePanel extends JPanel Implements Runnable
    public IncludePanel()
    this.addKeyListener(this);
         this.setFocusable(true);
    public void drawCircle( )
         th=new Thread(this);
         th.start();
    public synchronized void run()
              while(true)
    .......................// some logic which will call repaint method
    repaint();
    public void paintComponent(Graphics g)
              super.paintComponent(g);
              draw(g);
    public void draw(Graphics g)
              g.setColor(Color.red);
              g.drawLine(xx,yy,180,yy);
    My Problem is when my thread starts running at that time my KeyListener is not working.

    The code you posted is gibberish. I don't understand how you expect anyone to be able to help you from that.
    For instance: Your ShowFrame class implements KeyListener:
    public class ShowFrame extends JFrame implements KeyListener,ActionListenerbut it does not provide implementations for the KeyListener methods (as pointed out by the previous poster).
    Another example: Your IncludePanel does not implement KeyListener:
    public class IncludePanel extends JPanel Implements Runnablebut in its constructor you do this:
    public IncludePanel()
    this.addKeyListener(this);  // <------- "this" is not a KeyListenerSo, why don't you help us helping you by posting a short, compilable example program that demonstrates the problems you are having?

  • JSpinner and invalid values

    Hi guys !
    I have a JSpinner using the SpinnerNumberModel. I want to do the following:
    1- When the user enters an integer lower then the min value, it would automatically be set to the min value.
    2- When the user enters an integer higher then the max value, it would be set to the max value.
    3- When the user enters other characters (not integers), it would be set to the previous value (before the user typed).
    The default behavior of the SpinnerNumberModel is to just let it lay there when an invalid value is entered (until the focus leaves the spinner).
    I need to catch these invalid values (integer outside the range or non-integer characters) in other to respond correctly and change the value in the text field. Since these invalid values do not trigger the ChangeEvent event (thats the idea of the model I guess), I have tried catching them with an ActionEvent on the JFormattedTextField in the spinner but with no result.
    Or do I need to subclass the SpinnerNumberModel class ? And then how ?
    Or does it have to do with the JformattedTextField class ?
    Any idea someone ?

    I just realized if the user types in something that is not a number... it won't get committed... the spinner just reverts back to the last valid number. This is a good configuration (in case anyone ever reads this in the future):
        NumberEditor editor = (NumberEditor) spinner.getEditor();
        JFormattedTextField editorField = editor.getTextField();
        NumberFormatter formatter = (NumberFormatter) editorField.getFormatter();
        formatter.setOverwriteMode(true);
        formatter.setAllowsInvalid(true);
        formatter.setCommitsOnValidEdit(true);

  • JSpinner and addKeyListener (again)

    Hello
    I have already read in the forum (and in other places) that in order to get the key event, it is enough to grab the Model, apply getTextField() and then get the JFormattedTextField.
    The problem that is that, this works only if the focus is on the JTextField.
    If the focus is on the up/down arrows, I can't get the key event.
    What I am trying to do is this: if the user presses a button (e.g. the ALT button) to make the spinner go faster, when the user clicks on the arrow buttons.
    I have tried to grab the jey event in various positions, but with no luck.
    Any ideas / help?

    There is no direct API method to get at the buttons unless you start playing with the UI, but JSpinner is a container for the text field and the two buttons, so as a hack you should be able to use the Container.getComponent(...) method to get the button and add the listener to it.

  • JSpinner and BigDecimal , what am i doing wrong?

    hi,
    i'm trying to use a JSpinner to let the user input currencies.
    all my currencies are represented by BigDecimals.
    SpinnerNumberModel provides the following methodn which let's me think i can use BigDecimals in the spinner component:
    setStepSize(Number stepSize)
    The following code fails though :
    JSpinner spinner = new JSpinner();
    SpinnerNumberModel model = new SpinnerNumberModel();
    model.setStepSize(new BigDecimal("0.01");
    model.setValue(new BigDecimal("0.00");
    spinner.setModel(model);the spinner arrows don't work , and any value i enter is rejected
    what could be the problem ?

    From the SpinnerNumberModel API documentation:
    Internally, there's only support for values whose type is one of the primitive Number types: Double, Float, Long, Integer, Short, or Byte.

  • JMF and keylistener

    I guys, i'm new in jmf (fobs)world. I have coding a simple video player. My question is:
    is it possible to stop/play/pause the video whit keyboard? I'm thinking about keylistener but while the video is playing i can't I am not able to access the function to stop the video flow (is JMF blocking?).
    thanks in advance and sorry for my bad English
    regards.
    emanuele

    post your JMF question on that forum:
    http://forum.java.sun.com/forum.jspa?forumID=28

Maybe you are looking for

  • Style: reducing large diagrams, clearing wires, using subvis

    I've looked at the style guidelines by NI and read as many posts about LabVIEW style as I could find, but I'm still looking for more guidance on making clear, manageable diagrams for large programs. Any thoughts, common practices, or habits regarding

  • Custom Approval mechanism for file submit

    Hi, we want to have an approval mechanism for our own files in a customer project. The standard manage items with approval mechanism does not suit our needs, but can we make use of this approval feature in other ways? Is there some hidden Workflow in

  • HT1338 There is no three fingers options in the system references

    Hi guys I'm using  a MBP3,1 version 10 OS X 10.8.4 and I cannot find a three fingers options in the system references. What should I dot get this fixed? Please help!

  • How can I do something similar with Lightroom

    With the combination of the Editor of "Photoshop Elements" (PSE) and of the KODAK SHO Professional Plugin (which runs as a "filter"-plugin in the PSE Editor environment), I can often fixd photos which- - have both bright and dark portions - and which

  • Calling a program at the left of the screen

    Hi all I'm creating a program should allow to give a panoramic on certain business. At the right of the screen there's a tree where user can choose the function wants to run. At the left of the screen the user can see the result. Now I know how to lo