List of usage examples for javax.swing JScrollPane addComponentListener
public synchronized void addComponentListener(ComponentListener l)
From source file:com.googlecode.vfsjfilechooser2.filepane.VFSFilePane.java
public JPanel createDetailsView() { final VFSJFileChooser chooser = getFileChooser(); JPanel p = new JPanel(new BorderLayout()); final JTable detailsTable = new JTable(getDetailsTableModel()) { // Handle Escape key events here @Override/*from w w w .j a v a2 s . c o m*/ protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) && (getCellEditor() == null)) { // We are not editing, forward to filechooser. chooser.dispatchEvent(e); return true; } return super.processKeyBinding(ks, e, condition, pressed); } @Override public void tableChanged(TableModelEvent e) { super.tableChanged(e); if (e.getFirstRow() == TableModelEvent.HEADER_ROW) { // update header with possibly changed column set updateDetailsColumnModel(this); } } }; // detailsTable.setRowSorter(getRowSorter()); detailsTable.setAutoCreateColumnsFromModel(false); detailsTable.setComponentOrientation(chooser.getComponentOrientation()); //detailsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); detailsTable.setShowGrid(false); detailsTable.putClientProperty("JTable.autoStartsEdit", Boolean.FALSE); // detailsTable.addKeyListener(detailsKeyListener); Font font = list.getFont(); detailsTable.setFont(font); detailsTable.setIntercellSpacing(new Dimension(0, 0)); TableCellRenderer headerRenderer = new AlignableTableHeaderRenderer( detailsTable.getTableHeader().getDefaultRenderer()); detailsTable.getTableHeader().setDefaultRenderer(headerRenderer); TableCellRenderer cellRenderer = new DetailsTableCellRenderer(chooser); detailsTable.setDefaultRenderer(Object.class, cellRenderer); // So that drag can be started on a mouse press detailsTable.getColumnModel().getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); detailsTable.addMouseListener(getMouseHandler()); // No need to addListSelectionListener because selections are forwarded // to our JList. // 4835633 : tell BasicTableUI that this is a file list detailsTable.putClientProperty("Table.isFileList", Boolean.TRUE); if (listViewWindowsStyle) { detailsTable.addFocusListener(repaintListener); } JTableHeader header = detailsTable.getTableHeader(); header.setUpdateTableInRealTime(true); header.addMouseListener(detailsTableModel.new ColumnListener()); header.setReorderingAllowed(true); // TAB/SHIFT-TAB should transfer focus and ENTER should select an item. // We don't want them to navigate within the table ActionMap am = SwingUtilities.getUIActionMap(detailsTable); am.remove("selectNextRowCell"); am.remove("selectPreviousRowCell"); am.remove("selectNextColumnCell"); am.remove("selectPreviousColumnCell"); detailsTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null); detailsTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null); JScrollPane scrollpane = new JScrollPane(detailsTable); scrollpane.setComponentOrientation(chooser.getComponentOrientation()); LookAndFeel.installColors(scrollpane.getViewport(), "Table.background", "Table.foreground"); // Adjust width of first column so the table fills the viewport when // first displayed (temporary listener). scrollpane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { JScrollPane sp = (JScrollPane) e.getComponent(); fixNameColumnWidth(sp.getViewport().getSize().width); sp.removeComponentListener(this); } }); // 4835633. // If the mouse is pressed in the area below the Details view table, the // event is not dispatched to the Table MouseListener but to the // scrollpane. Listen for that here so we can clear the selection. scrollpane.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { JScrollPane jsp = ((JScrollPane) e.getComponent()); JTable table = (JTable) jsp.getViewport().getView(); if (!e.isShiftDown() || (table.getSelectionModel().getSelectionMode() == ListSelectionModel.SINGLE_SELECTION)) { clearSelection(); TableCellEditor tce = table.getCellEditor(); if (tce != null) { tce.stopCellEditing(); } } } }); detailsTable.setForeground(list.getForeground()); detailsTable.setBackground(list.getBackground()); if (listViewBorder != null) { scrollpane.setBorder(listViewBorder); } p.add(scrollpane, BorderLayout.CENTER); detailsTableModel.fireTableStructureChanged(); return p; }
From source file:org.nuxeo.launcher.gui.NuxeoFrame.java
/** * @param logFile/* ww w . j av a 2 s.c o m*/ */ protected JComponent buildLogPanel(String logFile) { ColoredTextPane textArea = new ColoredTextPane(); textArea.setEditable(false); textArea.setAutoscrolls(true); textArea.setBackground(new Color(54, 55, 67)); textArea.setMaxSize(LOG_MAX_SIZE); JScrollPane logsScroller = new JScrollPane(textArea); logsScroller.setVisible(true); logsScroller.setBorder(BorderFactory.createLineBorder(Color.BLACK)); logsScroller.setAutoscrolls(true); logsScroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); logsScroller.setWheelScrollingEnabled(true); logsScroller.setPreferredSize(new Dimension(450, 160)); controller.initLogsManagement(logFile, textArea); logsScroller.addComponentListener(new LogsPanelListener(logFile)); return logsScroller; }
From source file:org.pentaho.reporting.designer.core.ReportDesignerFrame.java
private JComponent createPaletteToolBar() { final JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false);//from w w w .j a v a 2 s .c om toolBar.setOrientation(JToolBar.VERTICAL); final ElementMetaData[] datas = ElementTypeRegistry.getInstance().getAllElementTypes(); Arrays.sort(datas, new GroupedMetaDataComparator()); Object grouping = null; boolean firstElement = true; for (int i = 0; i < datas.length; i++) { final ElementMetaData data = datas[i]; if (data.isHidden()) { continue; } if (!WorkspaceSettings.getInstance().isVisible(data)) { continue; } final String currentGrouping = data.getGrouping(Locale.getDefault()); if (firstElement == false) { if (ObjectUtilities.equal(currentGrouping, grouping) == false) { grouping = currentGrouping; toolBar.addSeparator(); } } else { grouping = currentGrouping; firstElement = false; } final InsertElementAction action = new InsertElementAction(data); action.setReportDesignerContext(context); toolBar.add(new PaletteButton(data, context)); } final JScrollPane paletteScrollpane = new JScrollPane(toolBar); paletteScrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); paletteScrollpane .addComponentListener(new ScrollbarSyncHandler(paletteScrollpane.getVerticalScrollBar(), toolBar)); return paletteScrollpane; }
From source file:shuffle.fwk.service.roster.EditRosterService.java
@SuppressWarnings("serial") private Component makeCenterPanel() { rosterEntryPanel = new JPanel(new WrapLayout()) { // Fix to make it play nice with the scroll bar. @Override//from w ww. ja v a 2s.co m 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; }
From source file:shuffle.fwk.service.teams.EditTeamService.java
@SuppressWarnings("serial") private Component makeTeamPanel() { JPanel firstOptionRow = new JPanel(new GridBagLayout()); GridBagConstraints rowc = new GridBagConstraints(); rowc.fill = GridBagConstraints.HORIZONTAL; rowc.weightx = 0.0;//from w w w . java2 s .co m rowc.weighty = 0.0; rowc.weightx = 1.0; rowc.gridx = 1; stageChooser = new StageChooser(this); firstOptionRow.add(stageChooser, rowc); rowc.weightx = 0.0; JPanel secondOptionRow = new JPanel(new GridBagLayout()); rowc.gridx = 1; JLabel megaLabel = new JLabel(getString(KEY_MEGA_LABEL)); megaLabel.setToolTipText(getString(KEY_MEGA_TOOLTIP)); secondOptionRow.add(megaLabel, rowc); rowc.gridx = 2; megaChooser = new JComboBox<String>(); megaChooser.setToolTipText(getString(KEY_MEGA_TOOLTIP)); secondOptionRow.add(megaChooser, rowc); rowc.gridx = 3; JPanel progressPanel = new JPanel(new BorderLayout()); megaActive = new JCheckBox(getString(KEY_ACTIVE)); megaActive.setSelected(false); megaActive.setToolTipText(getString(KEY_ACTIVE_TOOLTIP)); progressPanel.add(megaActive, BorderLayout.WEST); megaProgressChooser = new JComboBox<Integer>(); progressPanel.add(megaProgressChooser, BorderLayout.EAST); megaProgressChooser.setToolTipText(getString(KEY_MEGA_PROGRESS_TOOLTIP)); secondOptionRow.add(progressPanel, rowc); JPanel thirdOptionRow = new JPanel(new GridBagLayout()); rowc.gridx = 1; JButton clearTeamButton = new JButton(getString(KEY_CLEAR_TEAM)); clearTeamButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { clearTeam(); } }); clearTeamButton.setToolTipText(getString(KEY_CLEAR_TEAM_TOOLTIP)); thirdOptionRow.add(clearTeamButton, rowc); rowc.gridx = 2; woodCheckBox = new JCheckBox(getString(KEY_WOOD)); woodCheckBox.setToolTipText(getString(KEY_WOOD_TOOLTIP)); thirdOptionRow.add(woodCheckBox, rowc); rowc.gridx = 3; metalCheckBox = new JCheckBox(getString(KEY_METAL)); metalCheckBox.setToolTipText(getString(KEY_METAL_TOOLTIP)); thirdOptionRow.add(metalCheckBox, rowc); rowc.gridx = 4; coinCheckBox = new JCheckBox(getString(KEY_COIN)); coinCheckBox.setToolTipText(getString(KEY_COIN_TOOLTIP)); thirdOptionRow.add(coinCheckBox, rowc); rowc.gridx = 5; freezeCheckBox = new JCheckBox(getString(KEY_FREEZE)); freezeCheckBox.setToolTipText(getString(KEY_FREEZE_TOOLTIP)); thirdOptionRow.add(freezeCheckBox, rowc); JPanel topPart = new JPanel(new GridBagLayout()); GridBagConstraints topC = new GridBagConstraints(); topC.fill = GridBagConstraints.HORIZONTAL; topC.weightx = 0.0; topC.weighty = 0.0; topC.gridx = 1; topC.gridy = 1; topC.gridwidth = 1; topC.gridheight = 1; topC.anchor = GridBagConstraints.CENTER; topC.gridy = 1; topPart.add(firstOptionRow, topC); topC.gridy = 2; topPart.add(secondOptionRow, topC); topC.gridy = 3; topPart.add(thirdOptionRow, topC); addOptionListeners(); teamPanel = 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 scrollPane = new JScrollPane(teamPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) { @Override public Dimension getMinimumSize() { Dimension d = super.getMinimumSize(); d.width = topPart.getMinimumSize().width; d.height = rosterScrollPane.getPreferredSize().height - topPart.getPreferredSize().height; return d; } @Override public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); d.width = topPart.getMinimumSize().width; d.height = rosterScrollPane.getPreferredSize().height - topPart.getPreferredSize().height; return d; } }; scrollPane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { scrollPane.revalidate(); } }); scrollPane.getVerticalScrollBar().setUnitIncrement(27); JPanel ret = new JPanel(new GridBagLayout()); GridBagConstraints rc = new GridBagConstraints(); rc.fill = GridBagConstraints.VERTICAL; rc.weightx = 0.0; rc.weighty = 0.0; rc.gridx = 1; rc.gridy = 1; rc.insets = new Insets(5, 5, 5, 5); ret.add(topPart, rc); rc.gridy += 1; rc.weightx = 0.0; rc.weighty = 1.0; rc.insets = new Insets(0, 0, 0, 0); ret.add(scrollPane, rc); return ret; }