Java Code Examples for com.intellij.ui.components.JBScrollPane#setVerticalScrollBarPolicy()

The following examples show how to use com.intellij.ui.components.JBScrollPane#setVerticalScrollBarPolicy() . 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: KeyPromoterToolWindowFactory.java    From IntelliJ-Key-Promoter-X with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
    KeyPromoterToolWindowPanel toolWindowBuilder = new KeyPromoterToolWindowPanel();
    ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
    JBScrollPane toolWindowContent = new JBScrollPane(toolWindowBuilder.getContent());
    toolWindowContent.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    Content content = contentFactory.createContent(toolWindowContent, "", false);
    content.setPreferredFocusableComponent(toolWindowContent);
    content.setDisposer(toolWindowBuilder);
    toolWindow.getContentManager().addContent(content);
}
 
Example 2
Source File: CourseCard.java    From tmc-intellij with MIT License 4 votes vote down vote up
/**
 * This method is called from within the constructor to initialize the form. WARNING: Do NOT
 * modify this code. The content of this method is always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    titleLabel = new JLabel();
    nameLabel = new JLabel();
    infoScrollPane = new JBScrollPane();
    informationLabel = new JTextArea();

    setBackground(new Color(255, 255, 255));
    setMaximumSize(new Dimension(332, 73));
    setMinimumSize(new Dimension(332, 73));
    setPreferredSize(new Dimension(346, 107));

    titleLabel.setFont(new Font("Ubuntu", 1, 18)); // NOI18N

    nameLabel.setForeground(new Color(150, 150, 150));

    infoScrollPane.setBackground(new Color(255, 255, 255));
    infoScrollPane.setBorder(BorderFactory.createEmptyBorder(2, 10, 2, 10));
    infoScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    infoScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
    infoScrollPane.setViewportBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    infoScrollPane.setHorizontalScrollBar(null);
    infoScrollPane.setPreferredSize(new Dimension(106, 30));

    informationLabel.setEditable(false);
    informationLabel.setBackground(new Color(255, 255, 255));
    informationLabel.setLineWrap(true);
    informationLabel.setWrapStyleWord(true);
    informationLabel.setAutoscrolls(false);
    informationLabel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
    informationLabel.setMaximumSize(null);
    infoScrollPane.setViewportView(informationLabel);

    GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(
                            layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addGroup(
                                            layout.createParallelGroup(
                                                GroupLayout.Alignment.LEADING)
                                                    .addGroup(
                                                            layout.createSequentialGroup()
                                                                    .addComponent(titleLabel)
                                                                    .addPreferredGap(
                                                                            LayoutStyle
                                                                                    .ComponentPlacement
                                                                                    .RELATED,
                                                                            155,
                                                                            Short.MAX_VALUE)
                                                                    .addComponent(nameLabel))
                                                    .addComponent(
                                                            infoScrollPane,
                                                            GroupLayout.DEFAULT_SIZE,
                                                            GroupLayout.DEFAULT_SIZE,
                                                            Short.MAX_VALUE))
                                    .addContainerGap()));
    layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(
                            layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addGroup(
                                            layout.createParallelGroup(
                                                GroupLayout.Alignment.BASELINE)
                                                    .addComponent(titleLabel)
                                                    .addComponent(nameLabel))
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(
                                            infoScrollPane,
                                            GroupLayout.PREFERRED_SIZE,
                                            40,
                                            GroupLayout.PREFERRED_SIZE)
                                    .addContainerGap(
                                            GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
}
 
Example 3
Source File: IntelliJExpandableSupport.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
protected Content prepare(@Nonnull Source field, @Nonnull Function<? super String, String> onShow) {
  Font font = field.getFont();
  FontMetrics metrics = font == null ? null : field.getFontMetrics(font);
  int height = metrics == null ? 16 : metrics.getHeight();
  Dimension size = new Dimension(height * 32, height * 16);

  JTextArea area = new JTextArea(onShow.fun(field.getText()));
  area.putClientProperty(Expandable.class, this);
  area.setEditable(field.isEditable());
  area.setBackground(field.getBackground());
  area.setForeground(field.getForeground());
  area.setFont(font);
  area.setWrapStyleWord(true);
  area.setLineWrap(true);
  copyCaretPosition(field, area);
  UIUtil.addUndoRedoActions(area);

  JLabel label = ExpandableSupport.createLabel(createCollapseExtension());
  label.setBorder(JBUI.Borders.empty(5, 0, 5, 5));

  JBScrollPane pane = new JBScrollPane(area);
  pane.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS);
  pane.getVerticalScrollBar().add(JBScrollBar.LEADING, label);
  pane.getVerticalScrollBar().setBackground(area.getBackground());

  Insets insets = field.getInsets();
  Insets margin = field.getMargin();
  if (margin != null) {
    insets.top += margin.top;
    insets.left += margin.left;
    insets.right += margin.right;
    insets.bottom += margin.bottom;
  }

  JBInsets.addTo(size, insets);
  JBInsets.addTo(size, pane.getInsets());
  pane.setPreferredSize(size);
  pane.setViewportBorder(insets != null ? createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right) : createEmptyBorder());
  return new Content() {
    @Nonnull
    @Override
    public JComponent getContentComponent() {
      return pane;
    }

    @Override
    public JComponent getFocusableComponent() {
      return area;
    }

    @Override
    public void cancel(@Nonnull Function<? super String, String> onHide) {
      if (field.isEditable()) {
        field.setText(onHide.fun(area.getText()));
        copyCaretPosition(area, field);
      }
    }
  };
}