Java Code Examples for javax.swing.JScrollPane#setMaximumSize()

The following examples show how to use javax.swing.JScrollPane#setMaximumSize() . 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: PreferencesDialog.java    From LoboBrowser with MIT License 6 votes vote down vote up
private Component createLeftPane() {
  final PreferencesTree prefsTree = this.preferencesTree;
  prefsTree.addTreeSelectionListener(new LocalTreeSelectionListener());
  final JScrollPane scrollPane = new JScrollPane(prefsTree);
  final Dimension size = new Dimension(150, 200);
  scrollPane.setPreferredSize(size);
  scrollPane.setMinimumSize(size);
  scrollPane.setMaximumSize(new Dimension(150, Short.MAX_VALUE));
  return scrollPane;
}
 
Example 2
Source File: GUIFilterConfig.java    From PacketProxy with Apache License 2.0 4 votes vote down vote up
private JComponent createComponent() {
	String[] menu = { "#", I18nString.get("Filter name"), I18nString.get("Filter") };
	int[] menu_width = { 40, 150, 610 };
	boolean[] fixed_map = { true, false, false };
	int[] align_map = { JLabel.RIGHT, JLabel.LEFT, JLabel.LEFT };
	project_model = new ProjectTableModel(menu, 0) {
		private static final long serialVersionUID = 1L;
		@Override
		public boolean isCellEditable(int row, int column) { return false; }
	};
	JPanel panel = new JPanel();

	table = new JTable(project_model);
	tableFixedColumnWidth(table, menu_width, fixed_map);
	tableAssignAlignment(table, align_map);
	//sorter = new TableRowSorter<ProjectTableModel>(project_model);
	//table.setRowSorter(sorter);
	for (int i = 0; i < menu.length; i++) {
		table.getColumn(menu[i]).setPreferredWidth(menu_width[i]);
	}
	((JComponent) table.getDefaultRenderer(Boolean.class)).setOpaque(true);

	JScrollPane scrollpane1 = new JScrollPane(table);
    scrollpane1.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
    scrollpane1.setBackground(Color.WHITE);

	panel.add(createTableButton());
	panel.add(scrollpane1);
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    panel.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
    panel.setBackground(Color.WHITE);
	panel.add(scrollpane1);
	
	//sort_field = new HintTextField("フィルタ文字列");
    //sort_field.getDocument().addDocumentListener(new DocumentListener() {
	//	@Override
	//	public void insertUpdate(DocumentEvent e) {
	//		sortByText(sort_field.getText());
	//	}
	//	@Override
	//	public void removeUpdate(DocumentEvent e) {
	//		sortByText(sort_field.getText());
	//	}
	//	@Override
	//	public void changedUpdate(DocumentEvent e) {
	//		sortByText(sort_field.getText());
	//	}
    //});
    //sort_field.setMaximumSize(new Dimension(Short.MAX_VALUE, sort_field.getPreferredSize().height));
    
    JPanel vpanel = new JPanel();
    vpanel.setLayout(new BoxLayout(vpanel, BoxLayout.Y_AXIS));
    vpanel.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
    //vpanel.add(sort_field);
    vpanel.add(panel);
	
	return vpanel;
}
 
Example 3
Source File: Utilities.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static void adjustScrollPaneSize(JScrollPane sp, JEditorPane editorPane) {
    int height;
    //logger.fine("createSingleLineEditor(): editorPane's margin = "+editorPane.getMargin());
    //logger.fine("createSingleLineEditor(): editorPane's insets = "+editorPane.getInsets());
    Dimension prefSize = sp.getPreferredSize();
    Insets borderInsets = sp.getBorder().getBorderInsets(sp);//sp.getInsets();
    EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(editorPane);
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("createSingleLineEditor(): editor UI = "+eui);
        if (eui != null) {
            logger.fine("createSingleLineEditor(): editor UI's line height = "+eui.getLineHeight());
            logger.fine("createSingleLineEditor(): editor UI's line ascent = "+eui.getLineAscent());
        }
    }
    if (eui != null) {
        height = eui.getLineHeight();
        if (height < eui.getLineAscent()) {
            height = (eui.getLineAscent()*4)/3; // Hack for the case when line height = 1
        }
    } else {
        java.awt.Font font = editorPane.getFont();
        java.awt.FontMetrics fontMetrics = editorPane.getFontMetrics(font);
        height = fontMetrics.getHeight();
        //logger.fine("createSingleLineEditor(): editor's font = "+font+" with metrics = "+fontMetrics+", leading = "+fontMetrics.getLeading());
        //logger.fine("createSingleLineEditor(): font's height = "+height);
    }
    height += getLFHeightAdjustment();
    //height += 2; // 2 for border
    if (logger.isLoggable(Level.FINE)) {
        logger.fine("createSingleLineEditor(): border vertical insets = "+borderInsets.bottom+" + "+borderInsets.top);
        logger.fine("createSingleLineEditor(): computed height = "+height+", prefSize = "+prefSize);
    }
    if (prefSize.height < height) {
        prefSize.height = height;
        sp.setPreferredSize(prefSize);
        sp.setMinimumSize(prefSize);
        sp.setMaximumSize(prefSize);
        java.awt.Container c = sp.getParent();
        logger.fine("createSingleLineEditor(): setting a new height of ScrollPane = "+height);
        if (c instanceof JComponent) {
            ((JComponent) c).revalidate();
        }
    }
}
 
Example 4
Source File: ProgressPanel.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ProgressPanel() {
  super();

  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  
  int width = 400;

  progressTotal = new SafeJProgressBar();
  progressTotal.setAlignmentX(CENTER_ALIGNMENT);
  progressTotal.setMaximumSize(
      new Dimension(width, progressTotal.getPreferredSize().height));
  progressTotal.setIndeterminate(true);

  message = new JLabel("");
  message.setIcon(new ProgressIcon(48, 48));
  message.setHorizontalTextPosition(SwingConstants.RIGHT);
  message.setHorizontalAlignment(SwingConstants.CENTER);
  message.setAlignmentX(CENTER_ALIGNMENT);

  dlMsg = new JLabel("Downloading CREOLE Plugin...");
  dlMsg.setIcon(new DownloadIcon(48, 48));
  dlMsg.setHorizontalTextPosition(SwingConstants.RIGHT);
  dlMsg.setHorizontalAlignment(SwingConstants.CENTER);
  dlMsg.setAlignmentX(CENTER_ALIGNMENT);
  dlMsg.setVisible(false);

  partProgress = new JPanel();
  partProgress.setLayout(new BoxLayout(partProgress, BoxLayout.Y_AXIS));

  scroller = new JScrollPane(partProgress);
  scroller.setAlignmentX(CENTER_ALIGNMENT);
  scroller.setMaximumSize(
      new Dimension(width, progressTotal.getPreferredSize().height*6));
  scroller.setPreferredSize(
      new Dimension(width, progressTotal.getPreferredSize().height*6));
  

  add(Box.createVerticalGlue());
  add(message);
  add(Box.createVerticalStrut(5));
  add(progressTotal);
  add(Box.createVerticalStrut(10));
  add(dlMsg);
  add(Box.createVerticalStrut(5));
  add(scroller);

  add(Box.createVerticalGlue());

  addComponentListener(this);
}
 
Example 5
Source File: AbstractSuggestionBoxValueCellEditor.java    From rapidminer-studio with GNU Affero General Public License v3.0 4 votes vote down vote up
private void makeComboBoxDropDownWider() {
	Object child = comboBox.getAccessibleContext().getAccessibleChild(0);
	BasicComboPopup popup = (BasicComboPopup) child;
	Insets borderInsets = popup.getBorder().getBorderInsets(popup);
	JList<?> list = popup.getList();
	Dimension preferred = list.getPreferredSize();

	IntUnaryOperator extractWidth = i -> comboBox.getRenderer()
			.getListCellRendererComponent(list, model.getElementAt(i), i, false, false)
			.getPreferredSize().width + 3;
	preferred.width = IntStream.range(0, model.getSize()).map(extractWidth)
			.reduce(comboBox.getWidth() - borderInsets.left - borderInsets.right, Integer::max);

	int itemCount = comboBox.getItemCount();
	int rowHeight = 10;
	if (itemCount > 0) {
		rowHeight = preferred.height / itemCount;
	}
	int maxHeight = comboBox.getMaximumRowCount() * rowHeight;
	preferred.height = Math.min(preferred.height, maxHeight);

	Container c = SwingUtilities.getAncestorOfClass(JScrollPane.class, list);
	JScrollPane scrollPane = (JScrollPane) c;

	scrollPane.setPreferredSize(preferred);
	scrollPane.setMaximumSize(preferred);

	if (popup.isShowing()) { // 
		// a little trick to fire Popup.showPopup method that takes care of correct display
		popup.setLocation(comboBox.getLocationOnScreen().x, popup.getLocationOnScreen().y - 1);
	}

	Dimension popupSize = new Dimension();
	popupSize.width = preferred.width + borderInsets.left + borderInsets.right;
	popupSize.height = preferred.height + borderInsets.top + borderInsets.bottom;
	Component parent = popup.getParent();
	if (parent != null) {
		parent.setSize(popupSize);
		parent.validate();
		parent.repaint();
	}
}
 
Example 6
Source File: DiceChooser.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
private void createComponents() {
  final JPanel diceButtonPanel = new JPanel();
  diceButtonPanel.setLayout(new BoxLayout(diceButtonPanel, BoxLayout.X_AXIS));
  diceButtonPanel.add(Box.createHorizontalStrut(40));
  for (int roll = 1; roll <= diceSides; roll++) {
    diceButtonPanel.add(Box.createHorizontalStrut(4));
    final int dieNum = roll;
    final DieType dieType = roll == hitAt ? DieType.HIT : DieType.MISS;
    final JButton button = new JButton(uiContext.getDiceImageFactory().getDieIcon(roll, dieType));
    button.addActionListener(e -> addDie(dieNum));
    buttons.add(button);
    button.setPreferredSize(
        new Dimension(DiceImageFactory.DIE_WIDTH + 4, DiceImageFactory.DIE_HEIGHT + 4));
    diceButtonPanel.add(button);
  }
  diceButtonPanel.add(Box.createHorizontalStrut(4));
  undoButton = new JButton(SwingAction.of("Undo", e -> removeLastDie()));
  diceButtonPanel.add(undoButton);
  diceButtonPanel.add(Box.createHorizontalStrut(40));
  diceCountLabel = new JLabel("Dice remaining:   ");
  final JPanel labelPanel = new JPanel();
  labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.X_AXIS));
  labelPanel.add(diceCountLabel);
  dicePanel = new JPanel();
  dicePanel.setBorder(BorderFactory.createLoweredBevelBorder());
  dicePanel.setLayout(new BoxLayout(dicePanel, BoxLayout.X_AXIS));
  final JScrollPane scroll = new JScrollPane(dicePanel);
  scroll.setBorder(null);
  scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
  // we're adding to a box layout, so to prevent the component from grabbing extra space, set the
  // max height.
  // allow room for a dice and a scrollbar
  scroll.setMinimumSize(
      new Dimension(scroll.getMinimumSize().width, DiceImageFactory.DIE_HEIGHT + 17));
  scroll.setMaximumSize(
      new Dimension(scroll.getMaximumSize().width, DiceImageFactory.DIE_HEIGHT + 17));
  scroll.setPreferredSize(
      new Dimension(scroll.getPreferredSize().width, DiceImageFactory.DIE_HEIGHT + 17));
  add(scroll);
  add(Box.createVerticalStrut(8));
  add(labelPanel);
  add(Box.createVerticalStrut(8));
  add(diceButtonPanel);
  updateDiceCount();
}
 
Example 7
Source File: ProgressLog.java    From stendhal with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new page.
 */
Page() {
	this.setLayout(new SBoxLayout(SBoxLayout.VERTICAL));
	JComponent panels = SBoxLayout.createContainer(SBoxLayout.HORIZONTAL, SBoxLayout.COMMON_PADDING);
	add(panels, SBoxLayout.constraint(SLayout.EXPAND_X,
			SLayout.EXPAND_Y));

	indexArea = new PrettyEditorPane();
	indexArea.addHyperlinkListener(this);

	indexScrollPane = new JScrollPane(indexArea);
	// Fixed width
	indexScrollPane.setMaximumSize(new Dimension(INDEX_WIDTH, Integer.MAX_VALUE));
	indexScrollPane.setMinimumSize(new Dimension(INDEX_WIDTH, 0));
	// Turn off caret following
	Caret caret = indexArea.getCaret();
	if (caret instanceof DefaultCaret) {
		((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
	}

	panels.add(indexScrollPane, SLayout.EXPAND_Y);

	contentArea = new PrettyEditorPane();
	// Does not need a listener. There should be no links

	contentScrollPane = new JScrollPane(contentArea);
	panels.add(contentScrollPane, SBoxLayout.constraint(SLayout.EXPAND_X,
			SLayout.EXPAND_Y));

	JComponent buttonBox = SBoxLayout.createContainer(SBoxLayout.HORIZONTAL, SBoxLayout.COMMON_PADDING);
	buttonBox.setAlignmentX(RIGHT_ALIGNMENT);
	buttonBox.setBorder(BorderFactory.createEmptyBorder(SBoxLayout.COMMON_PADDING,
			0, SBoxLayout.COMMON_PADDING, SBoxLayout.COMMON_PADDING));
	add(buttonBox);
	// A button for reloading the page contents
	JButton refresh = new JButton("Update");
	refresh.setMnemonic(KeyEvent.VK_U);
	refresh.setAlignmentX(Component.RIGHT_ALIGNMENT);
	refresh.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent event) {
			update();
		}
	});
	buttonBox.add(refresh);
	JButton closeButton = new JButton("Close");
	closeButton.setMnemonic(KeyEvent.VK_C);
	closeButton.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			getWindow().dispose();
		}
	});
	buttonBox.add(closeButton);
}
 
Example 8
Source File: QFixMessengerFrame.java    From quickfix-messenger with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void initLeftPanel()
{
	leftPanel = new JPanel();
	leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));

	// Sessions Panel
	sessionsList = new JList<Session>();
	appVersionsComboBox = new JComboBox<String>(
			QFixMessengerConstants.FIXT_APP_VERSIONS);
	JPanel sessionsPanel = new JPanel();
	sessionsPanel.setBorder(new TitledBorder("Current Sessions"));
	sessionsPanel.setLayout(new BorderLayout());

	initSessionsList();
	JScrollPane sessionsListScrollPane = new JScrollPane(sessionsList);
	sessionsListScrollPane.setPreferredSize(new Dimension(LEFT_PANEL_WIDTH,
			120));
	sessionsListScrollPane.setMaximumSize(sessionsListScrollPane
			.getPreferredSize());

	initAppVersionsComboBox();
	JPanel appVersionsPanel = new JPanel();
	appVersionsPanel.setLayout(new GridLayout(2, 1));
	appVersionsPanel.add(new JLabel("ApplVerID: "));
	appVersionsPanel.add(appVersionsComboBox);

	sessionsPanel.add(sessionsListScrollPane, BorderLayout.CENTER);
	sessionsPanel.add(appVersionsPanel, BorderLayout.SOUTH);

	// Prevent resize
	sessionsPanel.setMinimumSize(sessionsPanel.getPreferredSize());
	sessionsPanel.setMaximumSize(sessionsPanel.getPreferredSize());

	// Messages Panel
	messagesList = new JList<Message>();

	recentMessagesMap = new HashMap<>();
	recentMessagesListModel = new DefaultListModel<Message>();
	recentMessagesList = new JList<Message>(recentMessagesListModel);

	JPanel messagesPanel = new JPanel();
	messagesPanel.setBorder(new TitledBorder("Available Messages"));
	messagesPanel.setLayout(new BoxLayout(messagesPanel, BoxLayout.Y_AXIS));

	initMessagesList();

	JScrollPane messagesListScrollPane = new JScrollPane(messagesList);
	messagesListScrollPane.setPreferredSize(new Dimension(LEFT_PANEL_WIDTH,
			300));

	JScrollPane recentMessagesListScrollPane = new JScrollPane(
			recentMessagesList);
	messagesTabPane = new JTabbedPane();
	messagesTabPane.setPreferredSize(new Dimension(LEFT_PANEL_WIDTH, 300));
	messagesTabPane.addTab("All", messagesListScrollPane);
	messagesTabPane.addTab("Recent", recentMessagesListScrollPane);

	messagesPanel.add(messagesTabPane);

	leftPanel.add(sessionsPanel);
	leftPanel.add(messagesPanel);
	add(leftPanel, BorderLayout.WEST);
}
 
Example 9
Source File: LibraryPanel.java    From HubPlayer with GNU General Public License v3.0 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", "serial" })
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

	aScrollPanel = new JScrollPane();
	dataTable = new JTable();
	libraryTableModel = new LibraryTableModel();
	libraryOperation = new LibraryOperation();

	aToolBar = new JToolBar();
	moreSearch = new JButton();

	setLayout(new BorderLayout());

	aScrollPanel
			.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
	aScrollPanel
			.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
	aScrollPanel.setMaximumSize(new Dimension(615, 481));

	// 设置20行空数据
	dataTable.setModel(libraryTableModel);
	libraryTableModel.setLibraryOperation(libraryOperation);

	// 定义"操作栏"的渲染器 显示按钮
	dataTable.getColumn("操作").setCellRenderer(
			new DefaultTableCellRenderer() {

				@Override
				public Component getTableCellRendererComponent(
						JTable table, Object value, boolean isSelected,
						boolean hasFocus, int row, int column) {

					return value instanceof JPanel ? (JPanel) value : super
							.getTableCellRendererComponent(table, value,
									isSelected, hasFocus, row, column);
				}
			});
	// 定义"操作栏"的编辑器 响应按钮事件
	dataTable.getColumn("操作").setCellEditor(new CellEditor());

	dataTable.setColumnSelectionAllowed(true);
	dataTable.setRowHeight(23);
	aScrollPanel.setViewportView(dataTable);
	dataTable.getColumnModel().getSelectionModel()
			.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

	add(aScrollPanel, BorderLayout.CENTER);

	aToolBar.setFloatable(false);
	aToolBar.setRollover(true);
	aToolBar.setOpaque(false);

	moreSearch.setText("更多数据");
	moreSearch.setFocusable(false);
	moreSearch.setHorizontalTextPosition(SwingConstants.CENTER);
	moreSearch.setVerticalTextPosition(SwingConstants.BOTTOM);
	// moreSearch.setEnabled(false);
	aToolBar.add(moreSearch);

	Box box = Box.createVerticalBox();
	box.setBorder(BorderFactory.createLineBorder(Color.BLACK));
	box.setOpaque(true);
	box.add(aToolBar);

	add(box, BorderLayout.SOUTH);

}