Java Code Examples for javax.swing.ScrollPaneConstants#HORIZONTAL_SCROLLBAR_ALWAYS

The following examples show how to use javax.swing.ScrollPaneConstants#HORIZONTAL_SCROLLBAR_ALWAYS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LWTextAreaPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
    final Dimension size = super.getMinimumSize(rows, columns);
    synchronized (getDelegateLock()) {
        // JScrollPane insets
        final Insets pi = getDelegate().getInsets();
        size.width += pi.left + pi.right;
        size.height += pi.top + pi.bottom;
        // Take scrollbars into account.
        final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
        if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
            size.width += vbar != null ? vbar.getMinimumSize().width : 0;
        }
        final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
        if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
            size.height += hbar != null ? hbar.getMinimumSize().height : 0;
        }
    }
    return size;
}
 
Example 2
Source File: LWTextAreaPeer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
    final Dimension size = super.getMinimumSize(rows, columns);
    synchronized (getDelegateLock()) {
        // JScrollPane insets
        final Insets pi = getDelegate().getInsets();
        size.width += pi.left + pi.right;
        size.height += pi.top + pi.bottom;
        // Take scrollbars into account.
        final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
        if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
            size.width += vbar != null ? vbar.getMinimumSize().width : 0;
        }
        final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
        if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
            size.height += hbar != null ? hbar.getMinimumSize().height : 0;
        }
    }
    return size;
}
 
Example 3
Source File: LWTextAreaPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
    final Dimension size = super.getMinimumSize(rows, columns);
    synchronized (getDelegateLock()) {
        // JScrollPane insets
        final Insets pi = getDelegate().getInsets();
        size.width += pi.left + pi.right;
        size.height += pi.top + pi.bottom;
        // Take scrollbars into account.
        final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
        if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
            size.width += vbar != null ? vbar.getMinimumSize().width : 0;
        }
        final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
        if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
            size.height += hbar != null ? hbar.getMinimumSize().height : 0;
        }
    }
    return size;
}
 
Example 4
Source File: TerminalPanel.java    From beast-mcmc with GNU Lesser General Public License v2.1 6 votes vote down vote up
public TerminalPanel() {

		// Setup miscallenous
		setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));

		// Setup text area
		textArea = new JTextArea();
		textArea.setEditable(true);
		textArea.setLineWrap(true);
		textArea.setWrapStyleWord(true);

		JScrollPane scrollPane = new JScrollPane(textArea,
				ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
				ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		add(scrollPane, BorderLayout.CENTER);

	}
 
Example 5
Source File: ThemeReaderCrashTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
ThemeReaderCrashTest() {
    JPanel panel = new JPanel();
    JScrollPane pane =
        new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    panel.setSize(300, 200);

    panel.add(pane);
}
 
Example 6
Source File: LWTextAreaPeer.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
    final Dimension size = super.getMinimumSize(rows, columns);
    synchronized (getDelegateLock()) {
        // JScrollPane insets
        final Insets pi = getDelegate().getInsets();
        size.width += pi.left + pi.right;
        size.height += pi.top + pi.bottom;
        // Take scrollbars into account.
        final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
        if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
            size.width += vbar != null ? vbar.getMinimumSize().width : 0;
        }
        final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
        if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
            size.height += hbar != null ? hbar.getMinimumSize().height : 0;
        }
    }
    return size;
}
 
Example 7
Source File: LWTextAreaPeer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
    final Dimension size = super.getMinimumSize(rows, columns);
    synchronized (getDelegateLock()) {
        // JScrollPane insets
        final Insets pi = getDelegate().getInsets();
        size.width += pi.left + pi.right;
        size.height += pi.top + pi.bottom;
        // Take scrollbars into account.
        final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
        if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
            size.width += vbar != null ? vbar.getMinimumSize().width : 0;
        }
        final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
        if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
            size.height += hbar != null ? hbar.getMinimumSize().height : 0;
        }
    }
    return size;
}
 
Example 8
Source File: LWTextAreaPeer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
    final Dimension size = super.getMinimumSize(rows, columns);
    synchronized (getDelegateLock()) {
        // JScrollPane insets
        final Insets pi = getDelegate().getInsets();
        size.width += pi.left + pi.right;
        size.height += pi.top + pi.bottom;
        // Take scrollbars into account.
        final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
        if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
            size.width += vbar != null ? vbar.getMinimumSize().width : 0;
        }
        final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
        if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
            size.height += hbar != null ? hbar.getMinimumSize().height : 0;
        }
    }
    return size;
}
 
Example 9
Source File: LWTextAreaPeer.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
    final Dimension size = super.getMinimumSize(rows, columns);
    synchronized (getDelegateLock()) {
        // JScrollPane insets
        final Insets pi = getDelegate().getInsets();
        size.width += pi.left + pi.right;
        size.height += pi.top + pi.bottom;
        // Take scrollbars into account.
        final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
        if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
            size.width += vbar != null ? vbar.getMinimumSize().width : 0;
        }
        final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
        if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
            size.height += hbar != null ? hbar.getMinimumSize().height : 0;
        }
    }
    return size;
}
 
Example 10
Source File: LWTextAreaPeer.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
    final Dimension size = super.getMinimumSize(rows, columns);
    synchronized (getDelegateLock()) {
        // JScrollPane insets
        final Insets pi = getDelegate().getInsets();
        size.width += pi.left + pi.right;
        size.height += pi.top + pi.bottom;
        // Take scrollbars into account.
        final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
        if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
            size.width += vbar != null ? vbar.getMinimumSize().width : 0;
        }
        final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
        if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
            size.height += hbar != null ? hbar.getMinimumSize().height : 0;
        }
    }
    return size;
}
 
Example 11
Source File: ClientGui.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private JScrollPane scroll(final JTextArea text) {
    final JToggleButton toggleButton = new JToggleButton();
    toggleButton.setAction(new AbstractAction() {
        private static final long serialVersionUID = -4214143754637722322L;

        @Override
        public void actionPerformed(final ActionEvent e) {
            final boolean wrap = toggleButton.isSelected();
            text.setLineWrap(wrap);
        }
    });
    toggleButton.setToolTipText("Toggle line wrapping");
    final JScrollPane scrollStatusLog = new JScrollPane(text, //
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, //
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollStatusLog.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, toggleButton);
    return scrollStatusLog;
}
 
Example 12
Source File: LWTextAreaPeer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
    final Dimension size = super.getMinimumSize(rows, columns);
    synchronized (getDelegateLock()) {
        // JScrollPane insets
        final Insets pi = getDelegate().getInsets();
        size.width += pi.left + pi.right;
        size.height += pi.top + pi.bottom;
        // Take scrollbars into account.
        final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
        if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
            size.width += vbar != null ? vbar.getMinimumSize().width : 0;
        }
        final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
        if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
            size.height += hbar != null ? hbar.getMinimumSize().height : 0;
        }
    }
    return size;
}
 
Example 13
Source File: LWTextAreaPeer.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
    final Dimension size = super.getMinimumSize(rows, columns);
    synchronized (getDelegateLock()) {
        // JScrollPane insets
        final Insets pi = getDelegate().getInsets();
        size.width += pi.left + pi.right;
        size.height += pi.top + pi.bottom;
        // Take scrollbars into account.
        final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
        if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
            size.width += vbar != null ? vbar.getMinimumSize().width : 0;
        }
        final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
        if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
            size.height += hbar != null ? hbar.getMinimumSize().height : 0;
        }
    }
    return size;
}
 
Example 14
Source File: LWTextAreaPeer.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
    final Dimension size = super.getMinimumSize(rows, columns);
    synchronized (getDelegateLock()) {
        // JScrollPane insets
        final Insets pi = getDelegate().getInsets();
        size.width += pi.left + pi.right;
        size.height += pi.top + pi.bottom;
        // Take scrollbars into account.
        final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
        if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
            size.width += vbar != null ? vbar.getMinimumSize().width : 0;
        }
        final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
        if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
            size.height += hbar != null ? hbar.getMinimumSize().height : 0;
        }
    }
    return size;
}
 
Example 15
Source File: LWTextAreaPeer.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Dimension getMinimumSize(final int rows, final int columns) {
    final Dimension size = super.getMinimumSize(rows, columns);
    synchronized (getDelegateLock()) {
        // JScrollPane insets
        final Insets pi = getDelegate().getInsets();
        size.width += pi.left + pi.right;
        size.height += pi.top + pi.bottom;
        // Take scrollbars into account.
        final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
        if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
            final JScrollBar vbar = getDelegate().getVerticalScrollBar();
            size.width += vbar != null ? vbar.getMinimumSize().width : 0;
        }
        final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
        if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
            final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
            size.height += hbar != null ? hbar.getMinimumSize().height : 0;
        }
    }
    return size;
}
 
Example 16
Source File: NoteEditor.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link Note} editor.
 *
 * @param note The {@link Note} to edit.
 */
public NoteEditor(Note note) {
    super(note);
    JPanel content   = new JPanel(new ColumnLayout(2, RowDistribution.GIVE_EXCESS_TO_LAST));
    JLabel iconLabel = new JLabel(note.getIcon(true));
    JPanel right     = new JPanel(new ColumnLayout(1, RowDistribution.GIVE_EXCESS_TO_LAST));
    content.add(iconLabel);
    content.add(right);

    mReferenceField = new JTextField(Text.makeFiller(6, 'M'));
    UIUtilities.setToPreferredSizeOnly(mReferenceField);
    mReferenceField.setText(note.getReference());
    mReferenceField.setToolTipText(Text.wrapPlainTextForToolTip(I18n.Text("A reference to the book and page this note applies to (e.g. B22 would refer to \"Basic Set\", page 22)")));
    mReferenceField.setEnabled(mIsEditable);
    JPanel wrapper = new JPanel(new ColumnLayout(4));
    wrapper.add(new LinkedLabel(I18n.Text("Note Content:")));
    wrapper.add(new JPanel());
    wrapper.add(new LinkedLabel(I18n.Text("Page Reference"), mReferenceField));
    wrapper.add(mReferenceField);
    right.add(wrapper);

    mEditor = new JTextArea(note.getDescription());
    mEditor.setLineWrap(true);
    mEditor.setWrapStyleWord(true);
    mEditor.setEnabled(mIsEditable);
    JScrollPane scroller = new JScrollPane(mEditor, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    scroller.setMinimumSize(new Dimension(400, 300));
    iconLabel.setVerticalAlignment(SwingConstants.TOP);
    iconLabel.setAlignmentY(-1.0f);
    right.add(scroller);

    add(content);
}
 
Example 17
Source File: ThemeReaderCrashTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
ThemeReaderCrashTest() {
    JPanel panel = new JPanel();
    JScrollPane pane =
        new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    panel.setSize(300, 200);

    panel.add(pane);
}
 
Example 18
Source File: DProviderInfo.java    From portecle with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize the dialog's GUI components.
 */
private void initComponents()
{
	// Buttons
	JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));

	JButton jbOK = getOkButton(true);
	jpButtons.add(jbOK);

	JButton jbCopy = new JButton(RB.getString("DProviderInfo.jbCopy.text"));
	jbCopy.setMnemonic(RB.getString("DProviderInfo.jbCopy.mnemonic").charAt(0));
	jbCopy.setToolTipText(RB.getString("DProviderInfo.jbCopy.tooltip"));
	jbCopy.addActionListener(new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent evt)
		{
			copyPressed();
		}
	});

	jpButtons.add(jbCopy);

	JPanel jpProviders = new JPanel(new BorderLayout());
	jpProviders.setBorder(new EmptyBorder(5, 5, 5, 5));

	// Load tree with info on loaded security providers
	JTree jtrProviders = new JTree(createProviderNodes());
	// Top accommodate node icons with spare space (they are 16 pixels tall)
	jtrProviders.setRowHeight(18);
	jtrProviders.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	// Allow tool tips in tree
	ToolTipManager.sharedInstance().registerComponent(jtrProviders);
	// Custom tree node renderer
	jtrProviders.setCellRenderer(new ProviderTreeCellRend());

	JScrollPane jspProviders = new JScrollPane(jtrProviders, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
	    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
	jspProviders.setPreferredSize(new Dimension(350, 200));
	jpProviders.add(jspProviders, BorderLayout.CENTER);

	getContentPane().add(jpProviders, BorderLayout.CENTER);
	getContentPane().add(jpButtons, BorderLayout.SOUTH);

	setTitle(RB.getString("DProviderInfo.Title"));

	getRootPane().setDefaultButton(jbOK);

	initDialog();

	setResizable(true);
	jbOK.requestFocusInWindow();
}
 
Example 19
Source File: DThrowableDetail.java    From portecle with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize the dialog's GUI components.
 */
private void initComponents()
{
	// Buttons
	JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));

	JButton jbOK = getOkButton(true);
	jpButtons.add(jbOK);

	JButton jbCopy = new JButton(RB.getString("DThrowableDetail.jbCopy.text"));
	jbCopy.setMnemonic(RB.getString("DThrowableDetail.jbCopy.mnemonic").charAt(0));
	jbCopy.setToolTipText(RB.getString("DThrowableDetail.jbCopy.tooltip"));
	jbCopy.addActionListener(new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent evt)
		{
			copyPressed();
		}
	});
	jpButtons.add(jbCopy);

	JPanel jpThrowable = new JPanel(new BorderLayout());
	jpThrowable.setBorder(new EmptyBorder(5, 5, 5, 5));

	// Load tree with info on throwable's stack trace
	JTree jtrThrowable = new JTree(createThrowableNodes());
	// Top accommodate node icons with spare space (they are 16 pixels tall)
	jtrThrowable.setRowHeight(18);
	jtrThrowable.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
	// Allow tool tips in tree
	ToolTipManager.sharedInstance().registerComponent(jtrThrowable);
	// Custom tree node renderer
	jtrThrowable.setCellRenderer(new ThrowableTreeCellRend());

	// Expand all nodes in tree
	/*
	 * ...then again, not. Too much scary detail. TreeNode topNode = (TreeNode)jtrThrowable.getModel().getRoot();
	 * expandTree(jtrThrowable, new TreePath(topNode));
	 */

	JScrollPane jspThrowable = new JScrollPane(jtrThrowable, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
	    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
	jspThrowable.setPreferredSize(new Dimension(500, 250));
	jpThrowable.add(jspThrowable, BorderLayout.CENTER);

	getContentPane().add(jpThrowable, BorderLayout.CENTER);
	getContentPane().add(jpButtons, BorderLayout.SOUTH);

	setTitle(RB.getString("DThrowableDetail.Title"));

	getRootPane().setDefaultButton(jbOK);

	initDialog();

	setResizable(true);
	jbOK.requestFocusInWindow();
}
 
Example 20
Source File: ListSelector.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Instantiates a new list selector.
 *
 * @param listData the list data
 */
public ListSelector(Object[] listData) {
  for (int i = 0; i < listData.length; i++)
    listModel.addElement(listData[i]);

  setLayout(new BorderLayout(4, 4));
  list = new JList(listModel);
  list.setFixedCellWidth(200);
  list.setVisibleRowCount(3);
  list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  Border etchedBorder = BorderFactory.createEtchedBorder();
  list.setBorder(etchedBorder);

  JScrollPane scrollPane = new JScrollPane(list, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
          ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
  add(scrollPane, BorderLayout.CENTER);

  JPanel controlPanel = new JPanel();
  GridBagLayout gbl = new GridBagLayout();
  GridBagConstraints gbc = new GridBagConstraints();
  gbc.insets = new Insets(2, 2, 2, 2);
  controlPanel.setLayout(gbl);

  addField = new JTextField(6);
  addField.addActionListener(this);

  gbc.gridx = 0;
  gbc.gridy = 0;
  gbc.anchor = GridBagConstraints.NORTHEAST;
  controlPanel.add(addField, gbc);

  gbc.gridx = 1;
  gbc.anchor = GridBagConstraints.NORTHWEST;

  addButton = new SmallButton("Add");
  addButton.addActionListener(this);
  controlPanel.add(addButton, gbc);

  gbc.gridx = 0;
  gbc.gridy = 1;
  gbc.anchor = GridBagConstraints.WEST;

  JPanel movePanel = new JPanel();
  movePanel.setLayout(new GridLayout(1, 2, 4, 4));

  moveUpButton = new ImageButton(Images.UP);
  moveUpButton.addActionListener(this);
  movePanel.add(moveUpButton);

  moveDownButton = new ImageButton(Images.DOWN);
  moveDownButton.addActionListener(this);
  movePanel.add(moveDownButton);

  controlPanel.add(movePanel, gbc);

  gbc.gridx = 1;
  gbc.anchor = GridBagConstraints.WEST;

  gbc.anchor = GridBagConstraints.WEST;
  removeButton = new SmallButton("Remove");
  removeButton.addActionListener(this);
  controlPanel.add(removeButton, gbc);

  add(controlPanel, BorderLayout.EAST);
}