Add a scroll-control on the spinner

This commit is contained in:
Arthur7770 2021-03-30 16:04:09 +02:00
parent 7fcd7d4449
commit d50b4f0042
2 changed files with 13 additions and 10 deletions

View File

@ -7,13 +7,10 @@ import lsystem.utils.Pair;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.*;
import java.util.List;
public class Listener implements ActionListener, KeyListener {
public class Listener implements ActionListener, KeyListener, MouseWheelListener {
Tab tab;
MainFrame frame;
Integer index;
@ -145,4 +142,12 @@ public class Listener implements ActionListener, KeyListener {
public void resetNbAxioms(){
nbAxioms = 0;
}
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if(e.getWheelRotation() < 0)
tab.itSpinner.setValue(tab.itSpinner.getNextValue());
else
tab.itSpinner.setValue(tab.itSpinner.getPreviousValue());
}
}

View File

@ -8,7 +8,7 @@ public class Tab extends JPanel{
int nbTabs;
int nbRules;
JSpinner nbIterations,itSpinner;
public JSpinner itSpinner;
JTextField axiomeField,rulesField;
JTextArea axiomList,rulesList;;
JButton submitButton, close;
@ -22,12 +22,10 @@ public class Tab extends JPanel{
axiomList = textArea("Axiome : \n",nbTabs);
rulesList = textArea("Règles : \n",nbTabs+10);
nbIterations = new JSpinner();
nbIterations.setModel(new SpinnerNumberModel(1, 1, 15, 1));
JLabel itLabel = new JLabel("Nombre d'itérations : ");
itSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 30, 1));
((JSpinner.DefaultEditor) itSpinner.getEditor()).getTextField().setEditable(false);
itSpinner.addMouseWheelListener(new Listener(null,null,"Spinner",this));
JLabel axiome = new JLabel("Axiome :");
JLabel rules = new JLabel("Règle "+ nbRules+" :");