Java Code Examples for javax.swing.ScrollPaneConstants#VERTICAL_SCROLLBAR_AS_NEEDED

The following examples show how to use javax.swing.ScrollPaneConstants#VERTICAL_SCROLLBAR_AS_NEEDED . 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: NoteInfoPane.java    From pcgen with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void initComponents()
{
	setLayout(new BorderLayout());

	Box hbox = Box.createHorizontalBox();
	hbox.add(Box.createRigidArea(new Dimension(5, 0)));
	hbox.add(new JLabel(LanguageBundle.getString("in_descNoteName"))); //$NON-NLS-1$
	hbox.add(Box.createRigidArea(new Dimension(5, 0)));
	hbox.add(nameField);
	nameField.setText(name);
	hbox.add(Box.createRigidArea(new Dimension(5, 0)));
	hbox.add(removeButton);
	hbox.add(Box.createHorizontalGlue());

	noteField.setLineWrap(true);
	noteField.setWrapStyleWord(true);

	add(hbox, BorderLayout.NORTH);
	JScrollPane pane = new JScrollPane(noteField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
		ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	add(pane, BorderLayout.CENTER);
}
 
Example 2
Source File: PlaRomData.java    From Logisim with GNU General Public License v3.0 6 votes vote down vote up
public int editWindow() {
	this.drawing = new PlaRomPanel(this);
	panel = new JScrollPane(this.drawing, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
			ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	panel.setBorder(null);
	panel.getVerticalScrollBar().setUnitIncrement(10);
	if (this.drawing.getPreferredSize().getWidth() >= (int) (screenSize.width * 0.75))
		panel.setPreferredSize(
				new Dimension((int) (screenSize.width * 0.75), (int) panel.getPreferredSize().getHeight()));
	if (this.drawing.getPreferredSize().getHeight() >= (int) (screenSize.height * 0.75))
		panel.setPreferredSize(
				new Dimension((int) panel.getPreferredSize().getWidth(), (int) (screenSize.height * 0.75)));
	int ret = JOptionPane.showOptionDialog(null, panel,
			Strings.getter("Logisim: Pla Rom " + getSizeString() + " Edit Window").get(),
			JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, this.options, null);
	SaveData();
	return ret;
}
 
Example 3
Source File: AboutDialogFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: ClientGUI.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Pops up a dialog box showing an alert
 */
public void doAlertDialog(String title, String message) {
    JTextPane textArea = new JTextPane();
    ReportDisplay.setupStylesheet(textArea);

    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    textArea.setText("<pre>" + message + "</pre>");
    scrollPane.setPreferredSize(new Dimension(
            (int) (getSize().getWidth() / 1.5), (int) (getSize()
                    .getHeight() / 1.5)));
    JOptionPane.showMessageDialog(frame, scrollPane, title,
            JOptionPane.ERROR_MESSAGE);
}
 
Example 5
Source File: SkinEditorMainGUI.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Pops up a dialog box showing an alert
 */
public void doAlertDialog(String title, String message) {
    JTextPane textArea = new JTextPane();
    ReportDisplay.setupStylesheet(textArea);

    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    textArea.setText("<pre>" + message + "</pre>");
    scrollPane.setPreferredSize(new Dimension(
            (int) (getSize().getWidth() / 1.5), (int) (getSize()
                    .getHeight() / 1.5)));
    JOptionPane.showMessageDialog(frame, scrollPane, title,
            JOptionPane.ERROR_MESSAGE);
}
 
Example 6
Source File: LipidClassComponent.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the component.
 *
 * @param theChoices the choices available to the user.
 */
public LipidClassComponent(final Object[] theChoices) {

  super(new BorderLayout());

  setBorder(BorderFactory.createEmptyBorder(0, 9, 0, 0));

  // Create choices panel.
  choices = Arrays.stream(theChoices).filter(o -> o instanceof LipidClasses)
      .map(o -> (LipidClasses) o).toArray(LipidClasses[]::new);
  choicesPanel = new JScrollPane(new CheckBoxPanel(theChoices),
      ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
      ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  choicesPanel.getViewport().setBackground(Color.WHITE);
  add(choicesPanel, BorderLayout.WEST);

  // Create Buttons panel.
  buttonsPanel = new JPanel();
  buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.Y_AXIS));
  add(buttonsPanel, BorderLayout.CENTER);

  // Add buttons.
  selectAllButton = new JButton("All");
  selectAllButton.setToolTipText("Select all choices");
  addButton(selectAllButton);
  selectNoneButton = new JButton("Clear");
  selectNoneButton.setToolTipText("Clear all selections");
  addButton(selectNoneButton);
}
 
Example 7
Source File: WhoIsPanel.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 5 votes vote down vote up
public WhoIsPanel(final ServiceFactory factory) {
	super(factory);
	final JPanel top = new JPanel();
	top.setLayout(new WrapLayout(FlowLayout.LEFT, 2, 0));
	_label = new JLabel("", SwingConstants.LEFT);
	top.add(_label);
	add(top, BorderLayout.NORTH);
	_textArea = new JTextArea("", 30, 70);
	_textArea.setEditable(false);
	final JScrollPane scroll = new JScrollPane(_textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	add(scroll, BorderLayout.CENTER);
	_whois.addListener(this);
}
 
Example 8
Source File: PacketDetailPanel.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Constructor
 * @param services
 */
@SuppressWarnings("serial")
public PacketDetailPanel(final ServiceFactory services) {
	super(services);
	setPreferredSize(new Dimension(getPreferredSize().width, 250));
	_details = new JTextPane() {
		@Override
		public boolean getScrollableTracksViewportWidth() {
			return getUI().getPreferredSize(this).width <= getParent().getSize().width;
		}
	};
	final JScrollPane scroll = new JScrollPane(_details, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	add(scroll, BorderLayout.CENTER);
}
 
Example 9
Source File: BotClient.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Pops up a dialog box showing an alert
 */
public void doAlertDialog(String title, String message) {
    JTextPane textArea = new JTextPane();
    ReportDisplay.setupStylesheet(textArea);

    textArea.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                                             ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    textArea.setText("<pre>" + message + "</pre>");
    JOptionPane.showMessageDialog(frame, scrollPane, title, JOptionPane.ERROR_MESSAGE);
}
 
Example 10
Source File: LuckComboboxPopup.java    From littleluck with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 11
Source File: SqlLoader.java    From CQL with GNU Affero General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: UnitSelectorDialog.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent ev) {
    if (ev.getSource().equals(comboWeight)
            || ev.getSource().equals(comboUnitType)) {
        filterUnits();
    } else if (ev.getSource().equals(btnSelect)) {
        select(false);
    } else if (ev.getSource().equals(btnSelectClose)) {
        select(true);
    } else if (ev.getSource().equals(btnClose)) {
        close();
    } else if (ev.getSource().equals(btnShowBV)) {
        JEditorPane tEditorPane = new JEditorPane();
        tEditorPane.setContentType("text/html");
        tEditorPane.setEditable(false);
        Entity e = getSelectedEntity();
        if (null == e) {
            return;
        }
        e.calculateBattleValue();
        tEditorPane.setText(e.getBVText());
        tEditorPane.setCaretPosition(0);
        JScrollPane tScroll = new JScrollPane(tEditorPane,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        Dimension size = new Dimension(550, 300);
        tScroll.setPreferredSize(size);
        JOptionPane.showMessageDialog(null, tScroll, "BV", JOptionPane.INFORMATION_MESSAGE, null);
    } else if(ev.getSource().equals(btnAdvSearch)) {
        searchFilter = asd.showDialog();
        btnResetSearch.setEnabled((searchFilter != null) && !searchFilter.isDisabled);
        filterUnits();
    } else if(ev.getSource().equals(btnResetSearch)) {
        asd.clearValues();
        searchFilter=null;
        btnResetSearch.setEnabled(false);
        filterUnits();
    }
}
 
Example 13
Source File: InfoPane.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
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();
}
 
Example 14
Source File: ServerSetupPanel.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
private void layoutPlayers() {
  final JPanel players = new JPanel();
  final GridBagLayout layout = new GridBagLayout();
  players.setLayout(layout);
  final Insets spacing = new Insets(3, 16, 0, 0);
  final Insets lastSpacing = new Insets(3, 16, 0, 16);
  int gridx = 0;
  final boolean disableable =
      !model.getPlayersAllowedToBeDisabled().isEmpty()
          || model.getPlayersEnabledListing().containsValue(Boolean.FALSE);
  final GridBagConstraints enabledPlayerConstraints = new GridBagConstraints();
  if (disableable) {
    enabledPlayerConstraints.anchor = GridBagConstraints.WEST;
    enabledPlayerConstraints.gridx = gridx++;
    enabledPlayerConstraints.insets = new Insets(3, 20, 0, -10);
  }
  final GridBagConstraints nameConstraints = new GridBagConstraints();
  nameConstraints.anchor = GridBagConstraints.WEST;
  nameConstraints.gridx = gridx++;
  nameConstraints.insets = spacing;
  final GridBagConstraints playerConstraints = new GridBagConstraints();
  playerConstraints.anchor = GridBagConstraints.WEST;
  playerConstraints.gridx = gridx++;
  playerConstraints.insets = spacing;
  final GridBagConstraints localConstraints = new GridBagConstraints();
  localConstraints.anchor = GridBagConstraints.WEST;
  localConstraints.gridx = gridx++;
  localConstraints.insets = spacing;
  final GridBagConstraints typeConstraints = new GridBagConstraints();
  typeConstraints.anchor = GridBagConstraints.WEST;
  typeConstraints.gridx = gridx++;
  typeConstraints.insets = spacing;
  final GridBagConstraints allianceConstraints = new GridBagConstraints();
  allianceConstraints.anchor = GridBagConstraints.WEST;
  allianceConstraints.gridx = gridx;
  allianceConstraints.insets = lastSpacing;
  if (disableable) {
    final JLabel enableLabel = new JLabel("Use");
    enableLabel.setForeground(Color.black);
    layout.setConstraints(enableLabel, enabledPlayerConstraints);
    players.add(enableLabel);
  }
  final JLabel nameLabel = new JLabel("Name");
  nameLabel.setForeground(Color.black);
  layout.setConstraints(nameLabel, nameConstraints);
  players.add(nameLabel);
  final JLabel playedByLabel = new JLabel("Played by");
  playedByLabel.setForeground(Color.black);
  layout.setConstraints(playedByLabel, playerConstraints);
  players.add(playedByLabel);
  final JLabel localLabel = new JLabel("Local");
  localLabel.setForeground(Color.black);
  layout.setConstraints(localLabel, localConstraints);
  players.add(localLabel);
  final JLabel typeLabel = new JLabel("Type");
  typeLabel.setForeground(Color.black);
  layout.setConstraints(typeLabel, typeConstraints);
  players.add(typeLabel);
  final JLabel allianceLabel = new JLabel("Alliance");
  allianceLabel.setForeground(Color.black);
  layout.setConstraints(allianceLabel, allianceConstraints);
  players.add(allianceLabel);
  if (playerRows.isEmpty()) {
    final JLabel noPlayers = new JLabel("Load a game file first");
    layout.setConstraints(noPlayers, nameConstraints);
    players.add(noPlayers);
  }
  for (final PlayerRow row : playerRows) {
    if (disableable) {
      layout.setConstraints(row.getEnabledPlayer(), enabledPlayerConstraints);
      players.add(row.getEnabledPlayer());
    }
    layout.setConstraints(row.getName(), nameConstraints);
    players.add(row.getName());
    layout.setConstraints(row.getPlayer(), playerConstraints);
    players.add(row.getPlayer());
    layout.setConstraints(row.getLocal(), localConstraints);
    players.add(row.getLocal());
    layout.setConstraints(row.getType(), typeConstraints);
    players.add(row.getType());
    layout.setConstraints(row.getAlliance(), allianceConstraints);
    players.add(row.getAlliance());
    row.getAlliance().addActionListener(e -> allianceRowButtonFired(row));
  }
  removeAll();
  add(info, BorderLayout.NORTH);
  final JScrollPane scroll =
      new JScrollPane(
          players,
          ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
          ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  scroll.setBorder(null);
  scroll.setViewportBorder(null);
  add(scroll, BorderLayout.CENTER);
  add(networkPanel, BorderLayout.SOUTH);
  invalidate();
  validate();
}
 
Example 15
Source File: ChartPagePanel.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 16
Source File: JCMInfo.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
JHTML(String s)
{
  super(new BorderLayout());

  html = new JTextPane();
  html.setEditable(false); // need to set this explicitly to fix swing 1.3 bug
  html.setCaretPosition(0);
  html.setContentType("text/html");

  // Enable posting of form submit events to the hyper link listener
  final HTMLEditorKit htmlEditor
  = (HTMLEditorKit)html.getEditorKitForContentType("text/html");
  try {
    // Call htmlEditor.setAutoFormSubmission(false); if available (Java 5+)
    final Method setAutoFormSubmissionMethod = htmlEditor.getClass()
      .getMethod("setAutoFormSubmission", new Class[]{ Boolean.TYPE});
    setAutoFormSubmissionMethod.invoke(htmlEditor,
                                       new Object[]{Boolean.FALSE});
  } catch (final Throwable t) {
    Activator.log.warn("Failed to enable auto form submission for JHTMLBundle.", t);
  }

  html.setText(s);
  html.setCaretPosition(0);

  html.addHyperlinkListener(new HyperlinkListener() {
    @Override
    public void hyperlinkUpdate(HyperlinkEvent ev)
    {
      if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        final URL url = ev.getURL();
        try {
          if (Util.isBundleLink(url)) {
            final long bid = Util.bidFromURL(url);
            Activator.disp.getBundleSelectionModel().clearSelection();
            Activator.disp.getBundleSelectionModel().setSelected(bid, true);
          } else if (Util.isImportLink(url)) {
            JCMInfo.importCfg(JHTML.this);
          } else {
            Util.openExternalURL(url);
          }
        } catch (final Exception e) {
          Activator.log.error("Failed to show " + url, e);
        }
      }
    }
  });

  scroll =
    new JScrollPane(html, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

  html.setPreferredSize(new Dimension(300, 300));

  add(scroll, BorderLayout.CENTER);
}
 
Example 17
Source File: TraceEventTypePopupMenu.java    From pega-tracerviewer with Apache License 2.0 4 votes vote down vote up
public JComponent getCheckBoxLabelMenuItemListJComponent() {

        JPanel checkBoxLabelMenuItemListJPanel = getCheckBoxLabelMenuItemListJPanel();

        JScrollPane jscrollPane = new JScrollPane(checkBoxLabelMenuItemListJPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        int vbarWidth = jscrollPane.getVerticalScrollBar().getPreferredSize().width;
        int hbarHeight = jscrollPane.getHorizontalScrollBar().getPreferredSize().height + 3/* border size */;

        int compWidth = checkBoxLabelMenuItemListJPanel.getPreferredSize().width;
        int compHeight = checkBoxLabelMenuItemListJPanel.getPreferredSize().height;

        int newCompWidth = compWidth + vbarWidth;
        int newCompHeight = compHeight + hbarHeight;

        Dimension newDim = new Dimension(newCompWidth, newCompHeight);

        jscrollPane.setPreferredSize(newDim);

        jscrollPane.getVerticalScrollBar().setUnitIncrement(14);

        return jscrollPane;
    }
 
Example 18
Source File: LogWindow.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Constructor
 */
public LogWindow(final Window parent) {
	super(parent, "Log", ModalityType.DOCUMENT_MODAL);
	final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
	for (final ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
		for (final Iterator<ch.qos.logback.core.Appender<ILoggingEvent>> index = logger.iteratorForAppenders(); index.hasNext();) {
			final ch.qos.logback.core.Appender<ILoggingEvent> appender = index.next();
			if (appender instanceof Appender) {
				_appender = (Appender) appender;
				break;
			}
		}
	}
	_logs = new JTextPane() {
		@Override
		public boolean getScrollableTracksViewportWidth() {
			return getUI().getPreferredSize(this).width <= getParent().getSize().width;
		}
	};
	if (_appender != null) {
		_appender.display = this;
	}
	try {
		for (final String line : Util.readUTF8File(new FileInputStream(Env.LOG_FILE))) {
			appendFormatted(line + "\n");
		}
	} catch (final FileNotFoundException e1) {
		appendFormatted("Failed to open file " + Env.LOG_FILE.getAbsolutePath());
	}
	final JScrollPane scroll = new JScrollPane(_logs, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	scroll.setPreferredSize(new Dimension(800, 600));
	getContentPane().add(scroll, BorderLayout.CENTER);
	final JButton close = new JButton(Resources.getLabel("close.button"));
	close.addActionListener(e -> LogWindow.this.dispose());
	getContentPane().add(close, BorderLayout.SOUTH);
	SwingUtilities4.setUp(this);
	getRootPane().registerKeyboardAction(e -> {
		_appender.display = null;
		dispose();
		if (parent != null) {
			parent.toFront();
		}
	}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
}
 
Example 19
Source File: DJarInfo.java    From portecle with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initialize the dialog's GUI components.
 *
 * @throws IOException Problem occurred getting JAR information
 */
private void initComponents()
    throws IOException
{
	JarFile[] jarFiles = getClassPathJars();

	// JAR Information table

	// Create the table using the appropriate table model
	JarInfoTableModel jiModel = new JarInfoTableModel();
	jiModel.load(jarFiles);

	JTable jtJarInfo = new JTable(jiModel);

	jtJarInfo.setRowMargin(0);
	jtJarInfo.getColumnModel().setColumnMargin(0);
	jtJarInfo.getTableHeader().setReorderingAllowed(false);
	jtJarInfo.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	jtJarInfo.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

	// Add custom renderers for the table cells and headers
	for (int iCnt = 0; iCnt < jtJarInfo.getColumnCount(); iCnt++)
	{
		TableColumn column = jtJarInfo.getColumnModel().getColumn(iCnt);

		column.setPreferredWidth(150);

		column.setHeaderRenderer(new JarInfoTableHeadRend());
		column.setCellRenderer(new JarInfoTableCellRend());
	}

	// Make the table sortable
	jtJarInfo.setAutoCreateRowSorter(true);
	// ...and sort it by jar file by default
	jtJarInfo.getRowSorter().toggleSortOrder(0);

	// Put the table into a scroll pane
	JScrollPane jspJarInfoTable = new JScrollPane(jtJarInfo, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
	    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	jspJarInfoTable.getViewport().setBackground(jtJarInfo.getBackground());

	// Put the scroll pane into a panel
	JPanel jpJarInfoTable = new JPanel(new BorderLayout(10, 10));
	jpJarInfoTable.setPreferredSize(new Dimension(500, 150));
	jpJarInfoTable.add(jspJarInfoTable, BorderLayout.CENTER);
	jpJarInfoTable.setBorder(new EmptyBorder(5, 5, 5, 5));

	JButton jbOK = getOkButton(true);
	JPanel jpOK = new JPanel(new FlowLayout(FlowLayout.CENTER));
	jpOK.add(jbOK);

	getContentPane().add(jpJarInfoTable, BorderLayout.CENTER);
	getContentPane().add(jpOK, BorderLayout.SOUTH);

	getRootPane().setDefaultButton(jbOK);

	initDialog();

	jbOK.requestFocusInWindow();
}
 
Example 20
Source File: PlayerChunkViewer.java    From ChickenChunks with MIT License 4 votes vote down vote up
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);
}