I have created using NetBeans
a jSlider ChangeEvent, with the following code:
public class Slider extends javax.swing.JFrame {
public Slider() {
initComponents;
field.getText();
String fieldVal = field.getText();
jtextField1.setText(fieldVal):
}
public JTextField getField() {
return field;
}
public void setField(JTextField field) {
this.field = field;
}
private void sliderStateChanged(javax.swing.event.ChangeEvent evt) {
int value = slider.getValue();
String val = value + "";
field.setText(val + "%");
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Slider().setVisible(true);
}
});
}
}
So, I have a JTextField
(field) who is receiving values from jSpiner. Everything works fine, but I want to take the "val" and make some computations with it.
But I can't do that, because it's in a private method, and I've tried to make it public, with Refactor -> Change
Method Parameters, but it gives me the following warning: Read-only block of text cannot be refactored., and it doesn't work.
I also have tried to make getters and setters, but still not working. All I want is to take that value. I could take it directly from JTextField (field) but I want to have "%" also in it so I can't do computations... Can someone please help me with an idea? I know that I'm wrong with something, but don't know where is the mistake. Or is a possibility to put "%" in the text field in other way? I need some help, thanks!
Best regards, Iulia