Java Code Examples for javax.swing.JList#setLayoutOrientation()

The following examples show how to use javax.swing.JList#setLayoutOrientation() . 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: LangSelector.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed (ActionEvent e)
{
    // Create a dialog with a JList of possible additions
    // That is all languages, minus those already desired
    List<String> additionals = new ArrayList<String>(
        Arrays.asList(OcrCompanion.ALL_LANGUAGES));
    additionals.removeAll(desired);

    JList<String> list = new JList(
        additionals.toArray(new String[additionals.size()]));
    JScrollPane   scrollPane = new JScrollPane(list);
    list.setLayoutOrientation(JList.VERTICAL_WRAP);
    list.setVisibleRowCount(10);

    // Let the user select additional languages
    int          opt = JOptionPane.showConfirmDialog(
        Installer.getFrame(),
        scrollPane,
        "OCR languages selection",
        JOptionPane.OK_CANCEL_OPTION,
        JOptionPane.QUESTION_MESSAGE);
    List<String> toAdd = list.getSelectedValuesList();
    logger.debug("Opt: {} Selection: {}", opt, toAdd);

    // Save the selection, only if OK
    if (opt == JOptionPane.OK_OPTION) {
        logger.info("Additional languages: {}", toAdd);
        desired.addAll(toAdd);

        // This may impact the "installed" status of the companion
        companion.checkInstalled();
        banner.defineLayout(null);
        companion.updateView();
    }
}
 
Example 2
Source File: SpringDemo.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private JComponent buildList() {
    Application[] elements = new Application[] {
        new Application("Address Book", "x-office-address-book.png"),
        new Application("Calendar",     "x-office-calendar.png"),
        new Application("Presentation", "x-office-presentation.png"),
        new Application("Spreadsheet",  "x-office-spreadsheet.png"),
    };
    
    list = new JList(elements);
    list.setCellRenderer(new ApplicationListCellRenderer());
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    list.setVisibleRowCount(2);
    list.setBorder(BorderFactory.createEtchedBorder());
    list.addMouseListener(new MouseAdapter() {
         public void mouseClicked(MouseEvent e) {
             if (e.getClickCount() == 2) {
                 int index = list.getSelectedIndex();
                 
                 Rectangle bounds = list.getCellBounds(index, index);
                 Point location = new Point(bounds.x, bounds.y);
                 location = SwingUtilities.convertPoint(list, location, glassPane);
                 location.y -= 13;
                 bounds.setLocation(location);
                 
                 glassPane.showSpring(bounds,
                         ((Application) list.getSelectedValue()).icon.getImage());
             }
         }
     });
    
    JPanel panel = new JPanel(new GridBagLayout());
    panel.add(new JLabel("Launcher"),
            new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
                GridBagConstraints.LINE_START, GridBagConstraints.NONE,
                new Insets(0, 0, 0, 0), 0, 0));
    panel.add(list, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
            GridBagConstraints.CENTER, GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0), 0, 0));
    panel.add(new JLabel("Double-click an icon to launch the program"),
            new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0,
                GridBagConstraints.LINE_START, GridBagConstraints.NONE,
                new Insets(0, 0, 0, 0), 0, 0));
    
    return panel;
}
 
Example 3
Source File: InstrumentBrowser.java    From jsyn with Apache License 2.0 4 votes vote down vote up
private void setupList(@SuppressWarnings("rawtypes") JList list) {
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list.setLayoutOrientation(JList.VERTICAL);
    list.setVisibleRowCount(-1);
}
 
Example 4
Source File: KeywordsListPane.java    From magarena with GNU General Public License v3.0 4 votes vote down vote up
KeywordsListPane(final KeywordPanelB keywordPanel) throws IOException {

        JList<Keyword> list = new JList<>(KeywordsHelper.getKeywords());

        list.setLayoutOrientation(JList.VERTICAL_WRAP);
        list.setVisibleRowCount(-1);

        list.setOpaque(false);
        list.setCellRenderer(new KeywordsListCellRenderer());

        list.setForeground(Color.WHITE);
        list.setFont(list.getFont().deriveFont(14f));

        list.addListSelectionListener((e) -> {
            final Keyword keyword = list.getSelectedValue();
            keywordPanel.setKeyword(keyword);
        });

        list.setSelectedIndex(0);

        setViewportView(list);

        setOpaque(false);
        getViewport().setOpaque(false);
    }
 
Example 5
Source File: InstrumentBrowser.java    From jsyn with Apache License 2.0 4 votes vote down vote up
private void setupList(@SuppressWarnings("rawtypes") JList list) {
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list.setLayoutOrientation(JList.VERTICAL);
    list.setVisibleRowCount(-1);
}
 
Example 6
Source File: ListParameterComponent.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Constructs a <code>JList</code> with an empty model.
 */
public ListParameterComponent( final ListParameter listParameter, final ParameterUpdateContext updateContext,
    final ParameterContext parameterContext ) {
  this.listParameter = listParameter;
  this.updateContext = updateContext;
  this.parameterContext = parameterContext;
  this.selectionCache = new ArrayList<Integer>();

  list = new JList();
  list.setCellRenderer( new FixedTheJDKListCellRenderer() );

  if ( listParameter.isAllowMultiSelection() ) {
    list.addListSelectionListener( new MultiValueListParameterHandler( listParameter.getName() ) );
    list.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
  } else {
    list.addListSelectionListener( new SingleValueListParameterHandler( listParameter.getName() ) );
    list.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
  }

  final String layout =
      listParameter.getParameterAttribute( ParameterAttributeNames.Core.NAMESPACE,
          ParameterAttributeNames.Core.LAYOUT, parameterContext );
  if ( "horizontal".equals( layout ) ) { //$NON-NLS-1$
    list.setLayoutOrientation( JList.HORIZONTAL_WRAP );
    list.setVisibleRowCount( 1 );
    list.setPreferredSize( new Dimension( (int) list.getMinimumSize().getWidth(), 25 ) );
  } else {
    final String visibleItemsText =
        listParameter.getParameterAttribute( ParameterAttributeNames.Core.NAMESPACE,
            ParameterAttributeNames.Core.VISIBLE_ITEMS, parameterContext );
    final int visibleItems = ParserUtil.parseInt( visibleItemsText, 0 );
    if ( visibleItems > 0 ) {
      list.setVisibleRowCount( visibleItems );
    }
  }

  setViewportView( list );
  getViewport().setMinimumSize( list.getPreferredScrollableViewportSize() );
  setHorizontalScrollBarPolicy( JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
  setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );

  changeListener = new ListUpdateHandler();
  updateContext.addChangeListener( changeListener );
}
 
Example 7
Source File: DataTable.java    From osp with GNU General Public License v3.0 4 votes vote down vote up
void setColumns(String[] names, String[] selected) {
  displayedNames = new String[names.length];
  realNames.clear();
	for (int i=0; i<names.length; i++) {
    String s = TeXParser.removeSubscripting(names[i]);
		// add white space for better look
		displayedNames[i] = "   "+s+" "; //$NON-NLS-1$ //$NON-NLS-2$
		realNames.put(displayedNames[i], names[i]);
  	if (selected!=null) {
   	for (int j=0; j<selected.length; j++) {
   		if (selected[j]!=null && selected[j].equals(names[i])) {
   			selected[j] = displayedNames[i];
   		}
   	}
  	}
	}
  prevPatterns.clear();
  for(String name : names) {
    prevPatterns.put(name, getFormatPattern(name));
  }
  // create column list and add to scroller
  columnList = new JList(displayedNames);
  columnList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
  columnList.setVisibleRowCount(-1);
  columnList.addListSelectionListener(new ListSelectionListener() {
  	public void valueChanged(ListSelectionEvent e) {
  		showNumberFormatAndSample(columnList.getSelectedIndices());
  	}
  });
  columnScroller.setViewportView(columnList);
  pack();
  int[] indices = null;
  if (selected!=null) {
    // select requested names
    indices = new int[selected.length];
    for (int j=0; j<indices.length; j++) {
    	inner:
     for (int i = 0; i< displayedNames.length; i++) {
     	if (displayedNames[i].equals(selected[j])) {
     		indices[j] = i;
     		break inner;
     	}
     }
    }
  	columnList.setSelectedIndices(indices);
  }
  else
    showNumberFormatAndSample(indices);
}