I'm making my really first "graphic" program in Java and almost all the components I used were added by dragging them into the NetBeans GUI, that's okay.
However, I had to add some code into a new void outside the famous: initComponents()
because I needed a JSlider which can interpret floats binded into a JTextField and viceversa, but that's not the main topic.
public AlbedoSection() {//Constructor
initComponents();//Generated by the GUI mostly
myInitComponents();//The void that I'm talking about
//which adds a custom Slider with a TextField
//But doesnt show up in the GUI Editor
}
public void myInitComponents() {
final DecimalFormat df = new DecimalFormat("0.####");
//final JFrame frame = new JFrame();
final JTextField text = new JTextField(20);
final DoubleJSlider slider = new DoubleJSlider(0, 10000, 0, 100);
slider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
text.setText(df.format(slider.getScaledValue()));
}
});
text.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent ke) {
String typed = text.getText();
double value = Double.parseDouble(typed) * slider.scale;
slider.setValue((int) value);
}
});
slider.setBounds(700,450,200,30);
text.setBounds(900,450,50,30);
add(text); //adding textfield into the frame
add(slider); // adding slider into the frame
}
I also set the components up and the program itsef works perfectly when I compile it, BUT the new "hardcoded" components doesn't seem to show up into the GUI Editor which led me to wonder If there's a way of doing that.
Forgive me If that's a stupid question, I'm just really new into programming.
EDIT1: Put two Images and Added code (the myInitComponents code is taken from here)