下面列出了javax.swing.ScrollPaneConstants#VERTICAL_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;
}
@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;
}
@SuppressWarnings("serial")
private Component makeRosterPanel() {
rosterPanel = new JPanel(new WrapLayout()) {
// Fix to make it play nice with the scroll bar.
@Override
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
d.width = (int) (d.getWidth() - 20);
return d;
}
};
rosterScrollPane = new JScrollPane(rosterPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
rosterScrollPane.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
rosterScrollPane.revalidate();
}
});
rosterScrollPane.getVerticalScrollBar().setUnitIncrement(27);
return rosterScrollPane;
}
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;
}
private JScrollPane setPanel (JTextArea outputPanel, String tabName)
// ---------------------------------------------------------------------------------//
{
outputPanel.setEditable (false);
outputPanel.setMargin (new Insets (5, 5, 5, 5));
JScrollPane outputScrollPane =
new JScrollPane (outputPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
outputScrollPane.setBorder (null); // remove the ugly default border
add (outputScrollPane, tabName);
return outputScrollPane;
}
@Override
public void startup() {
tree = new MyTree(root);
tree.setToggleClickCount(1000); // don't expand on double click hack
tree.addMouseListener(mouseListener);
tree.setCellRenderer(new TreeCellRenderer());
tree.setSelectionModel(null);
ToolTipManager.sharedInstance().registerComponent(tree);
JScrollPane scroll = new JScrollPane(tree, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
setLayout(new BorderLayout());
add(scroll, BorderLayout.CENTER);
Thread thread = new Thread() {
@Override
public void run() {
try {
populateTree();
} catch (RejectedExecutionException e) {
}
}
};
thread.setPriority(Thread.MIN_PRIORITY);
thread.start();
}
ThemeReaderCrashTest() {
JPanel panel = new JPanel();
JScrollPane pane =
new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
panel.setSize(300, 200);
panel.add(pane);
}
/**
* Create a JScrollPane.
*
* @param component Component inside the JScrollPane.
* @return JScrollPane.
*/
private JScrollPane createScrollPane(JComponent component) {
JScrollPane scrollPane = new JScrollPane(
component,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setPreferredSize(new Dimension(500, 400));
return scrollPane;
}
/**
* 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.
*
* @throws CryptoException A problem was encountered getting the object's PEM encoding
*/
private void initComponents()
throws CryptoException
{
if (m_pem == null)
{
StringWriter encoded = new StringWriter();
try (JcaPEMWriter pw = new JcaPEMWriter(encoded))
{
pw.writeObject(m_object);
}
catch (IOException e)
{
throw new CryptoException(RB.getString("DViewPEM.exception.message"), e);
}
m_pem = encoded.toString();
}
JPanel jpButtons = new JPanel(new FlowLayout(FlowLayout.CENTER));
JButton jbOK = getOkButton(true);
final JButton jbSave = new JButton(RB.getString("DViewPEM.jbSave.text"));
jbSave.setMnemonic(RB.getString("DViewPEM.jbSave.mnemonic").charAt(0));
if (m_chooser == null || m_pem == null)
{
jbSave.setEnabled(false);
}
else
{
jbSave.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent evt)
{
savePressed();
}
});
}
jpButtons.add(jbOK);
jpButtons.add(jbSave);
JPanel jpPEM = new JPanel(new BorderLayout());
jpPEM.setBorder(new EmptyBorder(5, 5, 5, 5));
// Load text area with the PEM encoding
JTextArea jtaPEM = new JTextArea(m_pem);
jtaPEM.setCaretPosition(0);
jtaPEM.setEditable(false);
jtaPEM.setFont(new Font(Font.MONOSPACED, Font.PLAIN, jtaPEM.getFont().getSize()));
JScrollPane jspPEM = new JScrollPane(jtaPEM, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jspPEM.setPreferredSize(new Dimension(500, 300));
jpPEM.add(jspPEM, BorderLayout.CENTER);
getContentPane().add(jpPEM, BorderLayout.CENTER);
getContentPane().add(jpButtons, BorderLayout.SOUTH);
getRootPane().setDefaultButton(jbOK);
initDialog();
setResizable(true);
jbOK.requestFocusInWindow();
}
public ExpressionTab(AnalyzerModel model) {
this.model = model;
selector = new OutputSelector(model);
model.getOutputExpressions().addOutputExpressionsListener(myListener);
selector.addItemListener(myListener);
clear.addActionListener(myListener);
revert.addActionListener(myListener);
enter.addActionListener(myListener);
field.setLineWrap(true);
field.setWrapStyleWord(true);
field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), myListener);
field.getDocument().addDocumentListener(myListener);
field.setFont(new Font("sans serif", Font.PLAIN, 14));
JPanel buttons = new JPanel();
buttons.add(clear);
buttons.add(revert);
buttons.add(enter);
GridBagLayout gb = new GridBagLayout();
GridBagConstraints gc = new GridBagConstraints();
setLayout(gb);
gc.weightx = 1.0;
gc.gridx = 0;
gc.gridy = GridBagConstraints.RELATIVE;
gc.fill = GridBagConstraints.BOTH;
JPanel selectorPanel = selector.createPanel();
gb.setConstraints(selectorPanel, gc);
add(selectorPanel);
gb.setConstraints(prettyView, gc);
add(prettyView);
gc.insets = new Insets(10, 10, 0, 10);
JScrollPane fieldPane = new JScrollPane(field, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
gb.setConstraints(fieldPane, gc);
add(fieldPane);
gb.setConstraints(buttons, gc);
add(buttons);
gc.fill = GridBagConstraints.BOTH;
gb.setConstraints(error, gc);
add(error);
myListener.insertUpdate(null);
setError(null);
}
public SelectionPanel(LogFrame window) {
super(window);
selector = new ComponentSelector(getModel());
addTool = new JButton();
changeBase = new JButton();
moveUp = new JButton();
moveDown = new JButton();
remove = new JButton();
removeAll = new JButton();
clearComponentLog = new JButton();
list = new SelectionList();
list.setSelection(getSelection());
JPanel buttons = new JPanel(new GridLayout(7, 1));
buttons.add(addTool);
buttons.add(changeBase);
buttons.add(moveUp);
buttons.add(moveDown);
buttons.add(remove);
buttons.add(removeAll);
buttons.add(clearComponentLog);
addTool.addActionListener(listener);
changeBase.addActionListener(listener);
moveUp.addActionListener(listener);
moveDown.addActionListener(listener);
remove.addActionListener(listener);
removeAll.addActionListener(listener);
clearComponentLog.addActionListener(listener);
selector.addMouseListener(listener);
selector.addTreeSelectionListener(listener);
list.addListSelectionListener(listener);
listener.computeEnabled();
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
setLayout(gridbag);
JScrollPane explorerPane = new JScrollPane(selector, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JScrollPane listPane = new JScrollPane(list, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gridbag.setConstraints(explorerPane, gbc);
add(explorerPane);
gbc.fill = GridBagConstraints.NONE;
gbc.anchor = GridBagConstraints.NORTH;
gbc.weightx = 0.0;
gridbag.setConstraints(buttons, gbc);
add(buttons);
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
gridbag.setConstraints(listPane, gbc);
add(listPane);
}
private JScrollPane getJScrollPane(TraceTable traceTable) {
JScrollPane jscrollpane = new JScrollPane(traceTable, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
traceTable.setPreferredScrollableViewportSize(jscrollpane.getPreferredSize());
return jscrollpane;
}