Example usage for javax.swing JSpinner JSpinner

List of usage examples for javax.swing JSpinner JSpinner

Introduction

In this page you can find the example usage for javax.swing JSpinner JSpinner.

Prototype

public JSpinner() 

Source Link

Document

Constructs a spinner with an Integer SpinnerNumberModel with initial value 0 and no minimum or maximum limits.

Usage

From source file:pcgen.gui2.dialog.PostLevelUpDialog.java

private void initComponents() {
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());
    JTable table = new JTable(tableModel) {

        @Override//from   w  ww. ja v a2 s.  c  o  m
        public TableCellEditor getCellEditor(int row, int column) {
            if (column == LevelTableModel.COL_ROLLED_HP && row < numLevels) {//TODO: the max roll should be calculated in a different manner
                String hd = levels.getClassTaken(levels.getElementAt(row + oldLevel)).getHD();
                int max = NumberUtils.toInt(hd);
                return new SpinnerEditor(new SpinnerNumberModel(1, 1, max, 1));
            }
            return super.getCellEditor(row, column);
        }

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
            if (column == LevelTableModel.COL_ROLLED_HP && row < numLevels) {
                return new SpinnerRenderer();
            }
            return super.getCellRenderer(row, column);
        }

    };
    table.setCellSelectionEnabled(false);
    table.setRowHeight(new JSpinner().getPreferredSize().height);
    JTableHeader header = table.getTableHeader();
    header.setReorderingAllowed(false);

    JScrollPane scrollPane = new JScrollPane(table);
    pane.add(scrollPane, BorderLayout.CENTER);

    Box box = Box.createHorizontalBox();
    box.add(Box.createHorizontalGlue());
    JButton button = new JButton(LanguageBundle.getString("in_close")); //$NON-NLS-1$
    button.setMnemonic(LanguageBundle.getMnemonic("in_mn_close")); //$NON-NLS-1$
    button.setActionCommand("Close"); //$NON-NLS-1$
    button.addActionListener(this);
    box.add(button);
    pane.add(box, BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            //Make sure to remove the listeners so that the garbage collector can
            //dispose of this dialog and prevent a memory leak
            levels.removeHitPointListener(tableModel);
        }

    });

    Utility.installEscapeCloseOperation(this);
}

From source file:yp.tibco.com.yang.lottery.client.GraphicalLotteryClient.java

private void initComponents() {
    JLabel jLabel1 = new JLabel();
    jTextFieldHost = new JTextField();
    jButtonConnect = new JButton();
    JLabel jLabel3 = new JLabel();
    jSpinnerWidth = new JSpinner();
    JLabel label5 = new JLabel();
    jSpinnerChars = new JSpinner();
    checkBoxContinuous = new JCheckBox();
    JLabel jLabel2 = new JLabel();
    jTextFieldPort = new JTextField();
    jButtonDisconnect = new JButton();
    JLabel jLabel4 = new JLabel();
    jSpinnerHeight = new JSpinner();
    jButtonSendRequest = new JButton();
    imagePanel1 = new LotteryPanel();

    //======== this ========
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setMinimumSize(new Dimension(700, 300));
    setPreferredSize(new Dimension(740, 600));
    Container contentPane = getContentPane();
    contentPane.setLayout(new GridBagLayout());
    ((GridBagLayout) contentPane.getLayout()).columnWidths = new int[] { 36, 167, 99, 41, 66, 75, 57, 96, 0,
            0 };/*  w w w  .j  a va2  s. c om*/
    ((GridBagLayout) contentPane.getLayout()).rowHeights = new int[] { 10, 31, 31, 256, 0 };
    ((GridBagLayout) contentPane.getLayout()).columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
            0.0, 1.0, 1.0E-4 };
    ((GridBagLayout) contentPane.getLayout()).rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, 1.0E-4 };

    //---- jLabel1 ----
    jLabel1.setText("Host");
    contentPane.add(jLabel1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0));
    contentPane.add(jTextFieldHost, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 5, 5, 10), 0, 0));

    //---- jButtonConnect ----
    jButtonConnect.setText("Connect");
    jButtonConnect.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            jButtonConnectActionPerformed();
        }
    });
    contentPane.add(jButtonConnect, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 5, 5, 10), 0, 0));

    //---- jLabel3 ----
    jLabel3.setText("Width");
    contentPane.add(jLabel3, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0));
    contentPane.add(jSpinnerWidth, new GridBagConstraints(4, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 5, 5, 10), 0, 0));

    //---- label5 ----
    label5.setText("characters");
    contentPane.add(label5, new GridBagConstraints(5, 1, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
            GridBagConstraints.VERTICAL, new Insets(0, 0, 5, 5), 0, 0));
    contentPane.add(jSpinnerChars, new GridBagConstraints(6, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 0, 5, 10), 0, 0));

    //---- checkBoxContinuous ----
    checkBoxContinuous.setText("continuous");
    contentPane.add(checkBoxContinuous, new GridBagConstraints(7, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 5, 5, 10), 0, 0));

    //---- jLabel2 ----
    jLabel2.setText("Port");
    contentPane.add(jLabel2, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 5, 5, 5), 0, 0));
    contentPane.add(jTextFieldPort, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 5, 5, 10), 0, 0));

    //---- jButtonDisconnect ----
    jButtonDisconnect.setText("Disconnect");
    jButtonDisconnect.setEnabled(false);
    jButtonDisconnect.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            jButtonDisconnectActionPerformed();
        }
    });
    contentPane.add(jButtonDisconnect, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 5, 5, 10), 0, 0));

    //---- jLabel4 ----
    jLabel4.setText("Height");
    contentPane.add(jLabel4, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0));
    contentPane.add(jSpinnerHeight, new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 5, 5, 10), 0, 0));

    //---- jButtonSendRequest ----
    jButtonSendRequest.setText("Send Request");
    jButtonSendRequest.setEnabled(false);
    jButtonSendRequest.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            jButtonSendRequestActionPerformed();
        }
    });
    contentPane.add(jButtonSendRequest, new GridBagConstraints(5, 2, 2, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(0, 5, 5, 10), 0, 0));

    //======== imagePanel1 ========
    {
        imagePanel1.setBackground(new Color(51, 153, 255));
        imagePanel1.setPreferredSize(new Dimension(500, 500));

        { // compute preferred size
            Dimension preferredSize = new Dimension();
            for (int i = 0; i < imagePanel1.getComponentCount(); i++) {
                Rectangle bounds = imagePanel1.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = imagePanel1.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            imagePanel1.setMinimumSize(preferredSize);
            imagePanel1.setPreferredSize(preferredSize);
        }
    }
    contentPane.add(imagePanel1, new GridBagConstraints(0, 3, 9, 1, 0.0, 0.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, new Insets(8, 5, 8, 5), 0, 0));
    pack();
    setLocationRelativeTo(getOwner());
}