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

The following examples show how to use com.intellij.ui.components.JBScrollPane#setViewportBorder() . 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: ScrollPaneFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static JScrollPane createScrollPane(Component view, boolean withoutBorder) {
  JBScrollPane scrollPane = new JBScrollPane(view);
  if (withoutBorder) {
    scrollPane.setBorder(IdeBorderFactory.createEmptyBorder()); // set empty border, because setting null doesn't always take effect
    scrollPane.setViewportBorder(IdeBorderFactory.createEmptyBorder());
  }
  return scrollPane;
}
 
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: DetailsPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
DetailsPanel(@Nonnull VcsLogData logData,
             @Nonnull VcsLogColorManager colorManager,
             @Nonnull Disposable parent) {
  myLogData = logData;
  myColorManager = colorManager;

  myScrollPane = new JBScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  myMainContentPanel = new ScrollablePanel() {
    @Override
    public boolean getScrollableTracksViewportWidth() {
      boolean expanded = false;
      for (Component c : getComponents()) {
        if (c instanceof CommitPanel && ((CommitPanel)c).isExpanded()) {
          expanded = true;
          break;
        }
      }
      return !expanded;
    }

    @Override
    public Dimension getPreferredSize() {
      Dimension preferredSize = super.getPreferredSize();
      int height = Math.max(preferredSize.height, myScrollPane.getViewport().getHeight());
      JBScrollPane scrollPane = UIUtil.getParentOfType(JBScrollPane.class, this);
      if (scrollPane == null || getScrollableTracksViewportWidth()) {
        return new Dimension(preferredSize.width, height);
      }
      else {
        return new Dimension(Math.max(preferredSize.width, scrollPane.getViewport().getWidth()), height);
      }
    }

    @Override
    public Color getBackground() {
      return CommitPanel.getCommitDetailsBackground();
    }

    @Override
    protected void paintChildren(Graphics g) {
      if (StringUtil.isNotEmpty(myEmptyText.getText())) {
        myEmptyText.paint(this, g);
      }
      else {
        super.paintChildren(g);
      }
    }
  };
  myEmptyText = new StatusText(myMainContentPanel) {
    @Override
    protected boolean isStatusVisible() {
      return StringUtil.isNotEmpty(getText());
    }
  };
  myMainContentPanel.setLayout(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, false));

  myMainContentPanel.setOpaque(false);
  myScrollPane.setViewportView(myMainContentPanel);
  myScrollPane.setBorder(IdeBorderFactory.createEmptyBorder());
  myScrollPane.setViewportBorder(IdeBorderFactory.createEmptyBorder());

  myLoadingPanel = new JBLoadingPanel(new BorderLayout(), parent, ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS) {
    @Override
    public Color getBackground() {
      return CommitPanel.getCommitDetailsBackground();
    }
  };
  myLoadingPanel.add(myScrollPane);

  setLayout(new BorderLayout());
  add(myLoadingPanel, BorderLayout.CENTER);

  myEmptyText.setText("Commit details");
}
 
Example 4
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);
      }
    }
  };
}