Hello So i have created a JFrame with a JSpinner inside (as you can see in the picture). Right now, the BorderLabel is showing in the Jspinner (as it should) but the arrows on the JSpinner are there as a part of the entire thing instead of just the JSpinner field. I would like help to find out how to put the JSpinner arrows on the bar. Thank you.
For you who asked for code,
Also I miss stated JLabel Earlier. I meant TitledBorder
import java.awt.ComponentOrientation;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
public class ex extends JFrame{
public static void main(String[] args){
new ex();
}
ex(){
super("test");
setSize(200,100);
SpinnerModel sm = new SpinnerNumberModel(3,1,25,1);
JSpinner shiftIn = new JSpinner(sm);
JPanel p = new JPanel();
shiftIn.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
shiftIn.setBorder(new CompoundBorder(new TitledBorder(new EmptyBorder(0,
0, 0, 0), "Shift Key"), shiftIn
.getBorder()));
p.add(shiftIn);
add(p);
setVisible(true);
}
}
This is not the sort of thing that a titled border was made for!
Use a
JLabel
and put it in thePAGE_START
of aBorderLayout
, put theJSpinner
in thePAGE_END
. Add that container (the panel) where the spinner is currently added. (Then add a mnemonic for the label and make it the 'label for' the spinner.)This is how to use that idea inside another layout (
GridLayout
in this example)..