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 javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.List; import java.util.List;
public class Listener implements ActionListener, KeyListener { public class Listener implements ActionListener, KeyListener, MouseWheelListener {
Tab tab; Tab tab;
MainFrame frame; MainFrame frame;
Integer index; Integer index;
@ -36,7 +33,7 @@ public class Listener implements ActionListener, KeyListener {
case "Close": case "Close":
frame.getTab().removeTabAt(index-1); frame.getTab().removeTabAt(index-1);
frame.decreaseTab(); frame.decreaseTab();
for(int i = 0; i <frame.getTab().getComponentCount(); i++){ for(int i = 0; i < frame.getTab().getComponentCount(); i++){
frame.getTab().setTitleAt(i,"Génération"+(i+1)); frame.getTab().setTitleAt(i,"Génération"+(i+1));
} }
@ -145,4 +142,12 @@ public class Listener implements ActionListener, KeyListener {
public void resetNbAxioms(){ public void resetNbAxioms(){
nbAxioms = 0; 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 nbTabs;
int nbRules; int nbRules;
JSpinner nbIterations,itSpinner; public JSpinner itSpinner;
JTextField axiomeField,rulesField; JTextField axiomeField,rulesField;
JTextArea axiomList,rulesList;; JTextArea axiomList,rulesList;;
JButton submitButton, close; JButton submitButton, close;
@ -22,12 +22,10 @@ public class Tab extends JPanel{
axiomList = textArea("Axiome : \n",nbTabs); axiomList = textArea("Axiome : \n",nbTabs);
rulesList = textArea("Règles : \n",nbTabs+10); 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 : "); JLabel itLabel = new JLabel("Nombre d'itérations : ");
itSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 30, 1)); itSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 30, 1));
((JSpinner.DefaultEditor) itSpinner.getEditor()).getTextField().setEditable(false); ((JSpinner.DefaultEditor) itSpinner.getEditor()).getTextField().setEditable(false);
itSpinner.addMouseWheelListener(new Listener(null,null,"Spinner",this));
JLabel axiome = new JLabel("Axiome :"); JLabel axiome = new JLabel("Axiome :");
JLabel rules = new JLabel("Règle "+ nbRules+" :"); JLabel rules = new JLabel("Règle "+ nbRules+" :");