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

The following examples show how to use javax.swing.JList#setPreferredSize() . 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: PlaceAddDevicesDialog.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Override
protected Component createContents() {
   JLabel label = new JLabel("Searching for devices to be added to the place, when pairing is successful you should hear the hub make a triple-beep");
   JButton done = new JButton("Done");
   done.addActionListener((event) -> submit());
   JList<DeviceAdvanced> list =
         Fields
            .<DeviceAdvanced>listBuilder()
            .withModel(model)
            .withRenderer((device) -> render(device), "")
            .labelled("devices")
            .build()
            .getComponent();
   list.setMinimumSize(new Dimension(0, 250));
   list.setPreferredSize(new Dimension(0, 250));

   JPanel panel = new JPanel(new BorderLayout());
   panel.add(label, BorderLayout.NORTH);
   panel.add(list, BorderLayout.CENTER);
   panel.add(done, BorderLayout.SOUTH);
   return panel;
}
 
Example 2
Source File: ReadLogsWindow.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 4 votes vote down vote up
private JList<String> logFilesList() {
	
	
	file = new File(System.getProperty("user.dir") + File.separator + "Logging Store/");
	
	final JFileChooser fileChooser = new JFileChooser();
	fileChooser.setCurrentDirectory(file);
	fileChooser.setMultiSelectionEnabled(true);

	final DefaultListModel<String> model = new DefaultListModel<String>();
	
	final JList<String> list = new JList<String>(model);
	list.setPreferredSize(new Dimension(85, 480));
	list.setFont(new Font("Dialog", Font.PLAIN, 12));
	list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	list.setSelectedIndex(0);
	list.setFixedCellHeight(18);
	list.addMouseListener(new MouseAdapter() {
		@Override
		public void mousePressed(MouseEvent e) {
			if (e.getClickCount() == 2) {
				selectedItem = list.getSelectedValue();
				getSelectedFileName();
			}
		}
	});
	
	list.setCellRenderer(new LogRecordsListRenderer());

	File[] selectedFiles = fileChooser.getCurrentDirectory().listFiles();

	for (File f : selectedFiles) {
		if (f.getName().indexOf(".log") != -1) {
			model.addElement(f.getName());
		}else {
			continue;
		}
	}
	if(model.isEmpty()) {
		model.addElement("List is empty!");
	}
	
	return list;
}
 
Example 3
Source File: CollectionSelectionDialog.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/** This method creates the GUI components and paces them into the layout*/
  protected void initGuiComponents(){
    this.getContentPane().setLayout(new BoxLayout(this.getContentPane(),
                                                  BoxLayout.Y_AXIS));
    // Create source label
    sourceLabel = new JLabel("Source");
    sourceLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
    // Create source list
    sourceList = new JList(sourceListModel);
    sourceList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    sourceList.setVisibleRowCount(10);
    sourceList.setAlignmentX(Component.LEFT_ALIGNMENT);

    // Create target label
    targetLabel = new JLabel("Target");
    targetLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
    // Create the target list
    targetList = new JList(targetListModel);
    targetList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    targetList.setVisibleRowCount(10);
    targetList.setAlignmentX(Component.LEFT_ALIGNMENT);
    targetList.setPreferredSize(sourceList.getPreferredSize());
    // Create Add >>  button
    addButton = new JButton(">>>");
    // Create Remove <<  button
    removeButton = new JButton("<<<");
    // Create ok button
    okButton = new JButton("Ok");
    // Create cancel button
    cancelButton = new JButton("Cancel");
    ///////////////////////////////////////
    // Arange components
    //////////////////////////////////////

    // Create the main box
    Box componentsBox = Box.createVerticalBox();
    componentsBox.add(Box.createRigidArea(new Dimension(0,5)));

    Box firstLevelBox = Box.createHorizontalBox();
    firstLevelBox.add(Box.createRigidArea(new Dimension(10,0)));
    // Add the Source list
    Box currentBox = Box.createVerticalBox();
    currentBox.add(sourceLabel);
    currentBox.add(new JScrollPane(sourceList));

    // Add the current box to the firstLevelBox
    firstLevelBox.add(currentBox);
    firstLevelBox.add(Box.createRigidArea(new Dimension(10,0)));

    // Add the add and remove buttons
    currentBox = Box.createVerticalBox();
    currentBox.add(addButton);
    currentBox.add(Box.createRigidArea(new Dimension(0,10)));
    currentBox.add(removeButton);

    // Add the remove buttons to the firstLevelBox
    firstLevelBox.add(currentBox);
    firstLevelBox.add(Box.createRigidArea(new Dimension(10,0)));

    // Add the target list
    currentBox = Box.createVerticalBox();
    currentBox.add(targetLabel);
    currentBox.add(new JScrollPane(targetList));

    // Add target list to the firstLevelBox
    firstLevelBox.add(currentBox);
    firstLevelBox.add(Box.createRigidArea(new Dimension(20,0)));

    // Add ok and cancel buttons to the currentBox
    currentBox = Box.createHorizontalBox();
    currentBox.add(Box.createHorizontalGlue());
    currentBox.add(okButton);
    currentBox.add(Box.createRigidArea(new Dimension(25,0)));
    currentBox.add(cancelButton);
    currentBox.add(Box.createHorizontalGlue());

    // Add all components to the components box
    componentsBox.add(firstLevelBox);
    componentsBox.add(Box.createRigidArea(new Dimension(0,10)));
    componentsBox.add(currentBox);
    componentsBox.add(Box.createRigidArea(new Dimension(0,5)));
    // Add the components box to the dialog
    this.getContentPane().add(componentsBox);
    this.pack();
}
 
Example 4
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 );
}