final JList list = new JList(model) { /** * @inherited <p> */ @Override public boolean getScrollableTracksViewportWidth() { return true; } }; list.setCellRenderer(new MyCellRenderer()); ComponentListener l = new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { // next line possible if list is of type JXList // list.invalidateCellSizeCache(); // for core: force cache invalidation by temporarily setting fixed height list.setFixedCellHeight(10); list.setFixedCellHeight(-1); } }; list.addComponentListener(l); add(new JScrollPane(list));
/** * @param keyword searchBar * @param result 搜索结果回调 */ public GlobalSearchDialog(String keyword, SearchFinishResult result) { setContentPane(contentPane); setModal(true); setTitle("Android Source Search"); setSize(800, 500); this.setLocationRelativeTo(null); listView.setModel(dataSet); listView.setFixedCellHeight(25); listView.addListSelectionListener(this); listView.addMouseListener(new ListDoubleClickEvent<String>(this)); searchBar.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { startSearch(); } }); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.searchFinishResult = result; if (!Utils.isEmpty(keyword)) { searchBar.setText(keyword); startSearch(); } }
imageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); imageList.setFixedCellWidth(240); imageList.setFixedCellHeight(120);
list.setVisibleRowCount(0); list.setFixedCellWidth(80); list.setFixedCellHeight(80); list.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
@Override public void componentResized(ComponentEvent e) { // Trick from kleopatra: // https://stackoverflow.com/questions/7306295/swing-jlist-with-multiline-text-and-dynamic-height // next line possible if list is of type JXList // list.invalidateCellSizeCache(); // for core: force cache invalidation by temporarily setting fixed height list.setFixedCellHeight(10); list.setFixedCellHeight(-1); }
static private JList<UserBit> createUserBitList( final ListModel<UserBit> model ) { final JList<UserBit> bitList = new SmoothTipList<>( model ); bitList.setFixedCellHeight( 20 ); return bitList; }
list.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { JList list = (JList)e.getComponent(); list.setFixedCellHeight(list.getVisibleRect().height / list.getModel().getSize()); } });
static private JList<PipeBitInfo> createPipeBitList( final ListModel<PipeBitInfo> model ) { final JList<PipeBitInfo> bitList = new SmoothTipList<>( model ); bitList.setCellRenderer( new BitCellRenderer() ); bitList.setFixedCellHeight( 20 ); return bitList; }
static private JList<PipeBitInfo> createPipeBitList( final ListModel<PipeBitInfo> model ) { final JList<PipeBitInfo> bitList = new SmoothTipList<>( model ); bitList.setCellRenderer( new PipeBitInfoRenderer() ); bitList.setFixedCellHeight( 20 ); return bitList; }
JList jlist = new JList(model); jlist.setVisibleRowCount(10); jlist.setFixedCellHeight(15); jlist.setFixedCellWidth(100);
public PreferencesPanel(Iterator<Preference> preferences) { this.setLayout(new GridBagLayout()); JLabel titleLabel = new JLabel(); titleLabel.setText(Res.getString("title.preferences")); titleLabel.setFont(new Font("Dialog", Font.BOLD, 15)); /* scrollPane is the left panel displaying the preference icons */ JScrollPane scrollPane = new JScrollPane( list ); scrollPane.setPreferredSize(new Dimension(125, 0)); scrollPane.setMinimumSize(new Dimension(125,100)); list.setFixedCellHeight(50); add( scrollPane, new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(5, 5, 5, 5), 50, 0)); add(flowPanel, new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); list.setCellRenderer(new JLabelIconRenderer()); list.addListSelectionListener(this); // Populate with current preferences while (preferences.hasNext()) { Preference preference = preferences.next(); listModel.addElement(new PreferenceUI(preference)); } list.setSelectedIndex(0); }
private JComponent createWestPanel() { final JTable fakeTable = new JTable(); final JTableHeader fakeHeader = fakeTable.getTableHeader(); final Component header = fakeHeader.getDefaultRenderer().getTableCellRendererComponent( fakeTable, "Available Pipe Bits", false, false, -1, -1 ); ((JLabel)header).setHorizontalAlignment( SwingConstants.CENTER ); _availablesList = createPipeBitList( _availablesListModel ); final JScrollPane scroll = new JScrollPane( _availablesList ); scroll.setColumnHeaderView( header ); scroll.setMinimumSize( new Dimension( 100, 10 ) ); final JList<PipeBitInfo> rowHeaders = new JList<>( _availablesListModel ); rowHeaders.setFixedCellHeight( 20 ); rowHeaders.setCellRenderer( new RoleRenderer() ); scroll.setRowHeaderView( rowHeaders ); scroll.setHorizontalScrollBarPolicy( ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER ); final JSplitPane split = new JSplitPane(); split.setLeftComponent( scroll ); split.setRightComponent( createInfoPlusPanel() ); split.setResizeWeight( 0.5 ); split.setDividerLocation( 0.4d ); return split; }
@Override protected ComboPopup createPopup() { return new BasicComboPopup(comboBox) { @Override protected JList createList() { JList list = super.createList(); Object prototypeValue = comboBox.getPrototypeDisplayValue(); if (prototypeValue != null) { ListCellRenderer renderer = comboBox.getRenderer(); Component rendererComponent = renderer .getListCellRendererComponent(list, prototypeValue, 0, false, false); if (rendererComponent instanceof JLabel) { // Preferred size of the renderer itself is (-1,-1) at this point, // so we need this hack Dimension prototypeSize = new JLabel(((JLabel) rendererComponent) .getText()).getPreferredSize(); list.setFixedCellHeight(prototypeSize.height); list.setFixedCellWidth(prototypeSize.width); } } return list; } }; }
public MessagesList() { super(); data = new DefaultListModel(); list = new JList(data); list.setPrototypeCellValue("................................................."); list.setFont(new java.awt.Font("Monospaced", 0, 10)); list.setFixedCellHeight(11); this.setAutoscrolls(true); this.getViewport().setView(list); }
private void propertiesChanged() { list.setFont(jEdit.getFontProperty("view.font")); list.setFixedCellHeight(list.getFontMetrics(list.getFont()) .getHeight()); } //}}}
private void computePopupBounds (Rectangle result, JLayeredPane lPane, int modelSize) { Dimension cSize = comboBar.getSize(); int width = getPopupWidth(); Point location = new Point(cSize.width - width - 1, comboBar.getBottomLineY() - 1); if (SwingUtilities.getWindowAncestor(comboBar) != null) { location = SwingUtilities.convertPoint(comboBar, location, lPane); } result.setLocation(location); // hack to make jList.getpreferredSize work correctly // JList is listening on ResultsModel same as us and order of listeners // is undefined, so we have to force update of JList's layout data jList1.setFixedCellHeight(15); jList1.setFixedCellHeight(-1); // end of hack jList1.setVisibleRowCount(modelSize); Dimension preferredSize = jList1.getPreferredSize(); preferredSize.width = width; preferredSize.height += statusPanel.getPreferredSize().height + 3; result.setSize(preferredSize); }
bucketList.setModel(bucketListModel); bucketList.setCellRenderer(new GcsBucketCellRenderer()); bucketList.setFixedCellHeight(25); bucketList.setBackground(bucketListPanel.getBackground());
private JComponent makeThreadsPanel() { JPanel panel = new JPanel( new BorderLayout() ); _cbThreads = new JComboBox<>(); _cbThreads.setBorder( BorderFactory.createMatteBorder( 1, 1, 1, 1, Scheme.active().getControlShadow() ) ); _cbThreads.setRenderer( new ThreadCellRenderer( _cbThreads.getRenderer() ) ); _cbThreads.addActionListener( action -> threadChanged() ); _cbThreads.setFocusable( false ); panel.add( _cbThreads, BorderLayout.NORTH ); DefaultListModel<StackFrameRef> model = new DefaultListModel<>(); _listFrames = new JList<>( model ); _listFrames.setBackground( Scheme.active().getWindow() ); _listFrames.getSelectionModel().setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); _listFrames.setFixedCellHeight( 22 ); _listFrames.setCellRenderer( new StackFrameCellRenderer() ); _listFrames.addListSelectionListener( e -> updateVars() ); JScrollPane scroller = new JScrollPane( _listFrames ); scroller.setBorder( null ); panel.add( scroller, BorderLayout.CENTER ); TabPane tabPane = new TabPane( TabPosition.TOP, TabPane.MINIMIZABLE | TabPane.RESTORABLE ); tabPane.addTab( "Threads", EditorUtilities.loadIcon( "images/thread.png" ), panel ); return tabPane; }
private void computePopupBounds (Rectangle result, JLayeredPane lPane, int modelSize) { Point location = new Point( comboBar.getIssueComponent().getX(), comboBar.getIssueComponent().getY() + comboBar.getIssueComponent().getHeight() - 1); location = SwingUtilities.convertPoint(comboBar, location, lPane); // XXX terrible hack! fix this result.setLocation(location); // hack to make jList.getpreferredSize work correctly // JList is listening on ResultsModel same as us and order of listeners // is undefined, so we have to force update of JList's layout data jList1.setFixedCellHeight(15); jList1.setFixedCellHeight(-1); // end of hack jList1.setVisibleRowCount(modelSize); Dimension preferredSize = jList1.getPreferredSize(); preferredSize.width = comboBar.getIssueComponent().getWidth(); preferredSize.height += statusPanel.getPreferredSize().height + 3; if(preferredSize.height > 150) { preferredSize.height = 150; } result.setSize(preferredSize); }
list.setFixedCellHeight(height);