下面列出了javax.swing.ScrollPaneConstants#HORIZONTAL_SCROLLBAR_NEVER 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private JScrollPane center() {
JEditorPane editorPane = new JEditorPane();
editorPane.setOpaque(false);
editorPane.setMargin(new Insets(0, 5, 2, 5));
editorPane.setContentType("text/html");
editorPane.setText(LICENSE_NOTICE);
editorPane.setEditable(false);
editorPane.addHyperlinkListener(hyperlinkListener);
JScrollPane scrollPane = new JScrollPane(editorPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setBorder(BorderFactory.createLineBorder(Color.gray));
SwingUtilities.invokeLater(() -> {
// Set the scroll bar position to top
scrollPane.getVerticalScrollBar().setValue(0);
});
return scrollPane;
}
private Component makeCenterPanel() {
speciesSelectPanel = new JPanel(new WrapLayout()) {
private static final long serialVersionUID = 5094314715314389100L;
// 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;
}
};
final JScrollPane ret = new JScrollPane(speciesSelectPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
ret.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
ret.revalidate();
}
});
ret.getVerticalScrollBar().setUnitIncrement(27);
return ret;
}
@SuppressWarnings("serial")
private Component makeCenterPanel() {
rosterEntryPanel = 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;
}
};
final JScrollPane ret = new JScrollPane(rosterEntryPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
ret.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
ret.revalidate();
}
});
ret.getVerticalScrollBar().setUnitIncrement(27);
return ret;
}
public HistogramTopComponent() {
initComponents();
setName(Bundle.CTL_HistogramTopComponent());
setToolTipText(Bundle.HINT_HistogramTopComponent());
controls = new HistogramControls(this);
add(controls, BorderLayout.SOUTH);
display = new HistogramDisplay(this);
final JScrollPane displayScroll = new JScrollPane(display, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
displayScroll.getVerticalScrollBar().setUnitIncrement(HistogramDisplay.MAXIMUM_BAR_HEIGHT);
add(displayScroll, BorderLayout.CENTER);
}
private static void doHelp() {
JTextArea jta = new JTextArea(help);
jta.setWrapStyleWord(true);
jta.setLineWrap(true);
JScrollPane p = new JScrollPane(jta, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
p.setPreferredSize(new Dimension(300, 200));
JOptionPane pane = new JOptionPane(p);
JDialog dialog = pane.createDialog(null, "Help on SQL Loader");
dialog.setModal(false);
dialog.setVisible(true);
dialog.setResizable(true);
}
@Override
public void startup() {
this.setLayout(new BorderLayout());
AbstractTableModel model = getModel();
table = getTable();
table.setModel(model);
table.getColumnModel().getColumn(0).setPreferredWidth(50);
table.getColumnModel().getColumn(1).setPreferredWidth(500);
scroll = new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
this.add(scroll, BorderLayout.CENTER);
}
@Override
protected JScrollPane createScroller()
{
// 滚动条悬浮在内容面板上的滚动面板
// Replace the original implementation with a custom scroll panel
// The scroll bar of the current scroll panel is suspended on the content
JScrollPane sp = new LuckScrollPane(list,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
sp.setHorizontalScrollBar(null);
return sp;
}
public InfoPane(String title)
{
super(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
String name = title;
if (title.startsWith("in_")) //$NON-NLS-1$
{
name = LanguageBundle.getString(title);
}
this.titledBorder =
BorderFactory.createTitledBorder(null, name, TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION);
this.textPane = new JTextPane();
initComponents();
}
public InfoPane(String title)
{
super(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
String name = title;
if (title.startsWith("in_")) //$NON-NLS-1$
{
name = LanguageBundle.getString(title);
}
this.titledBorder =
BorderFactory.createTitledBorder(null, name, TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION);
this.textPane = new JTextPane();
initComponents();
}
/**
* 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;
}
@Override
protected int getHorizontalScrollPolicy() {
return ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
}
@Override
protected int getHorizontalScrollPolicy() {
return ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
}
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);
}
VariableTab(VariableList data) {
this.data = data;
list.setModel(new VariableListModel(data));
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(myListener);
remove.addActionListener(myListener);
moveUp.addActionListener(myListener);
moveDown.addActionListener(myListener);
add.addActionListener(myListener);
rename.addActionListener(myListener);
field.addActionListener(myListener);
field.getDocument().addDocumentListener(myListener);
JScrollPane listPane = new JScrollPane(list, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
listPane.setPreferredSize(new Dimension(100, 100));
JPanel topPanel = new JPanel(new GridLayout(3, 1));
topPanel.add(remove);
topPanel.add(moveUp);
topPanel.add(moveDown);
JPanel fieldPanel = new JPanel();
fieldPanel.add(rename);
fieldPanel.add(add);
GridBagLayout gb = new GridBagLayout();
GridBagConstraints gc = new GridBagConstraints();
setLayout(gb);
gc.insets = new Insets(10, 10, 0, 10);
gc.fill = GridBagConstraints.BOTH;
gc.weightx = 1.0;
gb.setConstraints(listPane, gc);
add(listPane);
gc.fill = GridBagConstraints.NONE;
gc.anchor = GridBagConstraints.PAGE_START;
gc.weightx = 0.0;
gb.setConstraints(topPanel, gc);
add(topPanel);
gc.gridwidth = GridBagConstraints.REMAINDER;
gc.gridx = 0;
gc.gridy = GridBagConstraints.RELATIVE;
gc.fill = GridBagConstraints.HORIZONTAL;
gb.setConstraints(field, gc);
field.setBorder(BorderFactory.createLineBorder(new Color(130, 135, 144)));
add(field);
gb.setConstraints(fieldPanel, gc);
add(fieldPanel);
gc.fill = GridBagConstraints.HORIZONTAL;
gb.setConstraints(error, gc);
add(error);
if (!data.isEmpty())
list.setSelectedValue(data.get(0), true);
computeEnabled();
}
public HexFrame(Project proj, HexModel model) {
setDefaultCloseOperation(HIDE_ON_CLOSE);
LogisimMenuBar menubar = new LogisimMenuBar(this, proj);
setJMenuBar(menubar);
this.model = model;
this.editor = new HexEditor(model);
JPanel buttonPanel = new JPanel();
buttonPanel.add(open);
buttonPanel.add(save);
buttonPanel.add(close);
open.addActionListener(myListener);
save.addActionListener(myListener);
close.addActionListener(myListener);
Dimension pref = editor.getPreferredSize();
JScrollPane scroll = new JScrollPane(editor, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
pref.height = Math.min(pref.height, pref.width * 3 / 2);
scroll.setPreferredSize(pref);
scroll.getViewport().setBackground(editor.getBackground());
Container contents = getContentPane();
contents.add(scroll, BorderLayout.CENTER);
contents.add(buttonPanel, BorderLayout.SOUTH);
LocaleManager.addLocaleListener(myListener);
myListener.localeChanged();
pack();
setLocationRelativeTo(null);
Dimension size = getSize();
Dimension screen = getToolkit().getScreenSize();
if (size.width > screen.width || size.height > screen.height) {
size.width = Math.min(size.width, screen.width);
size.height = Math.min(size.height, screen.height);
setSize(size);
}
editor.getCaret().addChangeListener(editListener);
editor.getCaret().setDot(0, false);
editListener.register(menubar);
}
/**
* Sets up the frame that will display the editor.
*/
private void setupFrame() {
scrollPane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.getVerticalScrollBar().setUnitIncrement(12);
setFrameTitle();
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(bvc, BorderLayout.CENTER);
frame.getContentPane().add(scrollPane, BorderLayout.EAST);
menuBar.addActionListener(this);
frame.setJMenuBar(menuBar);
frame.setBackground(SystemColor.menu);
frame.setForeground(SystemColor.menuText);
if (GUIPreferences.getInstance().getWindowSizeHeight() != 0) {
frame.setLocation(GUIPreferences.getInstance().getWindowPosX(),
GUIPreferences.getInstance().getWindowPosY());
frame.setSize(GUIPreferences.getInstance().getWindowSizeWidth(),
GUIPreferences.getInstance().getWindowSizeHeight());
} else {
frame.setSize(800, 600);
}
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// When the board has changes, ask the user
if (hasChanges) {
ignoreHotKeys = true;
int savePrompt = JOptionPane.showConfirmDialog(null,
Messages.getString("BoardEditor.exitprompt"), //$NON-NLS-1$
Messages.getString("BoardEditor.exittitle"), //$NON-NLS-1$
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
ignoreHotKeys = false;
// When the user cancels or did not actually save the board, don't close
if (((savePrompt == JOptionPane.YES_OPTION) && !boardSave()) ||
(savePrompt == JOptionPane.CANCEL_OPTION)) {
return;
}
}
// otherwise: exit the Map Editor
minimapW.setVisible(false);
if (controller != null) {
controller.removeAllActions();
controller.boardEditor = null;
}
frame.dispose();
}
});
}
public TaxaEditor(MainFrame frame, PartitionDataList dataList, int row) {
this.frame = frame;
this.dataList = dataList;
this.row = row;
// taxonList = new Taxa();
taxaEditorTableModel = new TaxaEditorTableModel();
// Setup Main Menu buttons
load = new JButton("Load", Utils.createImageIcon(Utils.TEXT_FILE_ICON));
save = new JButton("Save", Utils.createImageIcon(Utils.SAVE_ICON));
done = new JButton("Done", Utils.createImageIcon(Utils.CHECK_ICON));
cancel = new JButton("Cancel", Utils.createImageIcon(Utils.CLOSE_ICON));
// Add Main Menu buttons listeners
load.addActionListener(new ListenLoadTaxaFile());
save.addActionListener(new ListenSaveTaxaFile());
done.addActionListener(new ListenOk());
cancel.addActionListener(new ListenCancel());
// Setup menu
menu = new JMenuBar();
menu.setLayout(new BorderLayout());
JPanel buttonsHolder = new JPanel();
buttonsHolder.setOpaque(false);
buttonsHolder.add(load);
buttonsHolder.add(save);
buttonsHolder.add(done);
buttonsHolder.add(cancel);
menu.add(buttonsHolder, BorderLayout.WEST);
// Setup table
table = new JTable();
table.setModel(taxaEditorTableModel);
table.setSurrendersFocusOnKeystroke(true);
JScrollPane scrollPane = new JScrollPane(table,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
RowNumberTable rowNumberTable = new RowNumberTable(table);
scrollPane.setRowHeaderView(rowNumberTable);
scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER,
rowNumberTable.getTableHeader());
ActionPanel actionPanel = new ActionPanel(false);
actionPanel.setAddAction(addTaxonAction);
actionPanel.setRemoveAction(removeTaxonAction);
// Setup window
owner = Utils.getActiveFrame();
window = new JDialog(owner, "Edit taxa set...");
window.getContentPane().add(menu, BorderLayout.NORTH);
window.getContentPane().add(scrollPane);
window.getContentPane().add(actionPanel, BorderLayout.SOUTH);
window.pack();
window.setLocationRelativeTo(owner);
setTaxa();
}
/**
* Responsible for creating the UI layout.
*
* @param chartPanel the panel of the chart
* @param optionsPanel the options panel for changing settings
* @param roiMaskSelector optional ROI mask selector, can be {@code null} if not wanted.
*/
protected void createUI(ChartPanel chartPanel, JPanel optionsPanel, RoiMaskSelector roiMaskSelector) {
this.roiMaskSelector = roiMaskSelector;
final JPanel extendedOptionsPanel = GridBagUtils.createPanel();
GridBagConstraints extendedOptionsPanelConstraints = GridBagUtils.createConstraints("insets.left=4,insets.right=2,anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2,weightx=1");
GridBagUtils.addToPanel(extendedOptionsPanel, new JSeparator(), extendedOptionsPanelConstraints, "gridy=0");
if (this.roiMaskSelector != null) {
GridBagUtils.addToPanel(extendedOptionsPanel, this.roiMaskSelector.createPanel(), extendedOptionsPanelConstraints, "gridy=1,insets.left=-4");
GridBagUtils.addToPanel(extendedOptionsPanel, new JPanel(), extendedOptionsPanelConstraints, "gridy=1,insets.left=-4");
}
GridBagUtils.addToPanel(extendedOptionsPanel, optionsPanel, extendedOptionsPanelConstraints, "insets.left=0,insets.right=0,gridy=2,fill=VERTICAL,fill=HORIZONTAL,weighty=1");
GridBagUtils.addToPanel(extendedOptionsPanel, new JSeparator(), extendedOptionsPanelConstraints, "insets.left=4,insets.right=2,gridy=5,anchor=SOUTHWEST");
final SimpleScrollPane optionsScrollPane = new SimpleScrollPane(extendedOptionsPanel,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
optionsScrollPane.setBorder(null);
optionsScrollPane.getVerticalScrollBar().setUnitIncrement(20);
final JPanel rightPanel = new JPanel(new BorderLayout());
rightPanel.add(createTopPanel(), BorderLayout.NORTH);
rightPanel.add(optionsScrollPane, BorderLayout.CENTER);
rightPanel.add(createChartBottomPanel(chartPanel), BorderLayout.SOUTH);
final ImageIcon collapseIcon = UIUtils.loadImageIcon("icons/PanelRight12.png");
final ImageIcon collapseRolloverIcon = ToolButtonFactory.createRolloverIcon(collapseIcon);
final ImageIcon expandIcon = UIUtils.loadImageIcon("icons/PanelLeft12.png");
final ImageIcon expandRolloverIcon = ToolButtonFactory.createRolloverIcon(expandIcon);
hideAndShowButton = ToolButtonFactory.createButton(collapseIcon, false);
hideAndShowButton.setToolTipText("Collapse Options Panel");
hideAndShowButton.setName("switchToChartButton");
hideAndShowButton.addActionListener(new ActionListener() {
private boolean rightPanelShown;
@Override
public void actionPerformed(ActionEvent e) {
rightPanel.setVisible(rightPanelShown);
if (rightPanelShown) {
hideAndShowButton.setIcon(collapseIcon);
hideAndShowButton.setRolloverIcon(collapseRolloverIcon);
hideAndShowButton.setToolTipText("Collapse Options Panel");
} else {
hideAndShowButton.setIcon(expandIcon);
hideAndShowButton.setRolloverIcon(expandRolloverIcon);
hideAndShowButton.setToolTipText("Expand Options Panel");
}
rightPanelShown = !rightPanelShown;
}
});
backgroundPanel = new JPanel(new BorderLayout());
backgroundPanel.add(chartPanel, BorderLayout.CENTER);
backgroundPanel.add(rightPanel, BorderLayout.EAST);
JLayeredPane layeredPane = new JLayeredPane();
layeredPane.add(backgroundPanel, new Integer(0));
layeredPane.add(hideAndShowButton, new Integer(1));
add(layeredPane);
}
public TicketInfoDialog(LinkedList<TicketInfo> tickets)
{
super(PlayerChunkViewer.this);
setModalityType(ModalityType.DOCUMENT_MODAL);
this.tickets = tickets;
infoPane = new JTextPane();
infoPane.setEditable(false);
infoPane.setOpaque(false);
infoPane.setContentType("text/html");
infoScrollPane = new JScrollPane(infoPane);
infoScrollPane.setOpaque(false);
add(infoScrollPane);
chunkPane = new JTextPane();
chunkPane.setEditable(false);
chunkPane.setOpaque(false);
chunkPane.setContentType("text/html");
chunkScrollPane = new JScrollPane(chunkPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
add(chunkScrollPane);
ticketComboBox = new JComboBox<String>();
for(TicketInfo ticket : tickets)
{
String ident = ticket.modId;
if(ticket.player != null)
ident += ", " + ticket.player;
ident += " #" + ticket.ID;
ticketComboBox.addItem(ident);
}
add(ticketComboBox);
addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
dialog = null;
}
});
setLayout(this);
setSize(getPreferredSize());
setLocationRelativeTo(null);
pack();
dialog = this;
setVisible(true);
}
/**
* A SwingTopComponent will have a JScrollPane by default, as it cannot know
* the expected layout of the given content. If you wish to remove the
* horizontal scroll bar, you can override this method to return
* JScrollPane.HORIZONTAL_SCROLLBAR_NEVER.
*
* @return an integer representing the desired horizontal scroll bar policy.
*/
protected int getHorizontalScrollPolicy() {
return ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
}