下面列出了javax.swing.ScrollPaneConstants#HORIZONTAL_SCROLLBAR_ALWAYS 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
@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;
}
@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;
}
@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;
}
@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;
}
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;
}
@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;
}
@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;
}
@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;
}
@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;
}
@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;
}
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);
}
@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;
}
@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;
}
ThemeReaderCrashTest() {
JPanel panel = new JPanel();
JScrollPane pane =
new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
panel.setSize(300, 200);
panel.add(pane);
}
/**
* 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);
}
ThemeReaderCrashTest() {
JPanel panel = new JPanel();
JScrollPane pane =
new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
panel.setSize(300, 200);
panel.add(pane);
}
/**
* 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);
}
/**
* 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();
}
/**
* 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();
}