JSpinner is to wide.

I am using a JSpinner within a Panel with the BoxLayout and numbers in the range of 1 to 200.

The JSpinner takes up the entire width of the JPanel.

How can I make the JSpinner as wide as three number digits or manually resize it?

I have tried setSize and setPreferedSize.

I have not found any usefull information in over 5 Java text books or on the web. JSpinner is mentioned but never how to size it.

I am at a loss.

Thanks in advance.

[479 byte] By [scottie_uka] at [2007-10-3 4:14:20]
# 1

> The JSpinner takes up the entire width of the JPanel.

You could try setting the maximum size equal to the preferred size.

If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.

And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the code retains its original formatting.

camickra at 2007-7-14 22:15:37 > top of Java-index,Desktop,Core GUI APIs...
# 2

Here we are.

Its only a small class afterall.

public class SettingsPanel extends JFrame{

private JTabbedPane settingsPanel = new JTabbedPane();

private JPanel variableTab = new JPanel();

private Dimension d = new Dimension(400,350);

//==========================================================================

//Class constructor

//==========================================================================

public SettingsPanel() {

try

{

jbInit();

} //end try

catch (Exception e)

{

e.printStackTrace();

}//end catch

}//=========================================================================

//==========================================================================

//Method: JbInit

//Initialise the settings panel class.

//==========================================================================

private void jbInit() throws Exception

{

this.setAlwaysOnTop(true);

this.setPreferredSize(d);

this.setSize(d);

this.setTitle("Advanced Settings");

settingsPanel.setPreferredSize(d);

setupVariableTab();

this.add(settingsPanel, null);

}//=========================================================================

//==========================================================================

//Method: setUpVariableTab

//Sets up the variable Tab

//==========================================================================

private void setupVariableTab() {

variableTab.setPreferredSize(d);

BoxLayout layout = new BoxLayout(variableTab,BoxLayout.Y_AXIS);

variableTab.setLayout(layout);

//Max Number of Variables============

JPanel jpNumOfVars = new JPanel();

SpinnerModel spinnerModel = new SpinnerNumberModel(50, 1, 200, 1);

JLabel jlNumOfVars = new JLabel();

jlNumOfVars.setText("Max Number of Variables");

variableTab.add(jlNumOfVars);

JSpinner jsNumOfVars = new JSpinner(spinnerModel);

// jsNumOfVars.setValue(new Integer(50));

//jsNumOfVars.setPreferredSize(new Dimension(50,100));

variableTab.add(jsNumOfVars);

variableTab.add(jpNumOfVars);

//Max Number of Arrays================

SpinnerModel spinnerModel1 = new SpinnerNumberModel(20, 1, 200, 1);

JLabel jlNumOfArrays = new JLabel();

jlNumOfArrays.setText("Max Number of Arrays");

variableTab.add(jlNumOfArrays);

JSpinner jsNumOfArrays= new JSpinner(spinnerModel1);

// jsNumOfArrays.setValue(new Integer(20));

//jsNumOfArrays.setPreferredSize(new Dimension(50,100));

variableTab.add(jpNumOfArrays);

//Variable Visual Repr=========

JLabel jlVariableView = new JLabel();

jlVariableView.setText("Variable Visual Representation");

variableTab.add(jlVariableView);

JRadioButton jrbTable = new JRadioButton("Table");

jrbTable.setOpaque(false);

JRadioButton jrbTree = new JRadioButton("Tree");

jrbTree.setOpaque(false);

variableTab.add(jrbTable);

variableTab.add(jrbTree);

//Direct Variable Input==================

JLabel jlVariableInput = new JLabel();

jlVariableInput.setText("Direct Value Entry");

variableTab.add(jlVariableInput);

JRadioButton jrbDirectEntryA = new JRadioButton("Enabled");

jrbTable.setOpaque(false);

JRadioButton jrbDirectEntryB = new JRadioButton("Disabled");

jrbTree.setOpaque(false);

variableTab.add(jrbDirectEntryA);

variableTab.add(jrbDirectEntryB);

variableTab.add(jpVariableInput);

}//=========================================================================

}//end of class========================================================================

Thanks

Andrew

scottie_uka at 2007-7-14 22:15:38 > top of Java-index,Desktop,Core GUI APIs...
# 3
> Its only a small class afterall.Yes, but it doesn't compile and therefore is not executable!
camickra at 2007-7-14 22:15:38 > top of Java-index,Desktop,Core GUI APIs...
# 4
also tryadd the spinner to a JPaneladd the panel to the boxlayoutPanel
Michael_Dunna at 2007-7-14 22:15:38 > top of Java-index,Desktop,Core GUI APIs...
# 5
Bingo Michael,Thanks, that done the trick!! Cheers all.
scottie_uka at 2007-7-14 22:15:38 > top of Java-index,Desktop,Core GUI APIs...