Example usage for javax.swing JList HORIZONTAL_WRAP

List of usage examples for javax.swing JList HORIZONTAL_WRAP

Introduction

In this page you can find the example usage for javax.swing JList HORIZONTAL_WRAP.

Prototype

int HORIZONTAL_WRAP

To view the source code for javax.swing JList HORIZONTAL_WRAP.

Click Source Link

Document

Indicates a "newspaper style" layout with cells flowing horizontally then vertically.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);
    JScrollPane scrollingList = new JScrollPane(list);

    // Change orientation to top-to-bottom, left-to-right layout
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
}

From source file:MainClass.java

public static void main(final String args[]) {
    final String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Multi-Columns");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList columns = new JList(labels);
    columns.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    columns.setVisibleRowCount(3);//from  ww  w.  j a  v a  2 s  .  co m
    JScrollPane sp = new JScrollPane(columns);
    frame.add(sp, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] items = { "A", "B", "C", "D" };
    JList list = new JList(items);
    JScrollPane scrollingList = new JScrollPane(list);

    // The default layout orientation is JList.VERTICAL
    int orient = list.getLayoutOrientation();

    // Change the layout orientation to left-to-right, top-to-bottom
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
}

From source file:Main.java

public static void main(String[] args) {
    DefaultListModel<String> model = new DefaultListModel<>();
    JList<String> sList = new JList<>(model);
    for (int i = 0; i < 100; i++) {
        model.addElement("String " + i);
    }//from   w w w.  j  a  v  a 2s  .  c o  m

    sList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    sList.setVisibleRowCount(-1);
    sList.setLayoutOrientation(JList.HORIZONTAL_WRAP);

    JFrame frame = new JFrame("Foo001");
    frame.getContentPane().add(new JScrollPane(sList));
    frame.getContentPane().setPreferredSize(new Dimension(400, 300));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:ListTest.java

public ListFrame() {
    setTitle("ListTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    String[] words = { "quick", "brown", "hungry", "wild", "silent", "huge", "private", "abstract", "static",
            "final" };

    wordList = new JList(words);
    wordList.setVisibleRowCount(4);//from   w w  w .j av a 2s  . c om
    JScrollPane scrollPane = new JScrollPane(wordList);

    listPanel = new JPanel();
    listPanel.add(scrollPane);
    wordList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            Object[] values = wordList.getSelectedValues();

            StringBuilder text = new StringBuilder(prefix);
            for (int i = 0; i < values.length; i++) {
                String word = (String) values[i];
                text.append(word);
                text.append(" ");
            }
            text.append(suffix);

            label.setText(text.toString());
        }
    });

    buttonPanel = new JPanel();
    group = new ButtonGroup();
    makeButton("Vertical", JList.VERTICAL);
    makeButton("Vertical Wrap", JList.VERTICAL_WRAP);
    makeButton("Horizontal Wrap", JList.HORIZONTAL_WRAP);

    add(listPanel, BorderLayout.NORTH);
    label = new JLabel(prefix + suffix);
    add(label, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);
}

From source file:fr.free.hd.servers.gui.PhonemView.java

@Override
protected JComponent createControl() {
    final JPanel view = new JPanel(new BorderLayout());

    Collection<Phonem> phonesList = phonemsDAO.getPhonems();
    Map<String, Phonem> mapList = new HashMap<String, Phonem>();
    for (Phonem phonem : phonesList) {
        mapList.put(phonem.getPhonem(), phonem);
    }/* ww  w.j a va 2 s  .c  om*/

    final StatementListModel model = new StatementListModel(mapList);

    printCommand.setModel(model);
    printCommand.setFace(face);
    copyCommand.setModel(model);
    copyCommand.setFace(face);

    list = new JList(model);
    final JScrollPane sp = new JScrollPane(list);
    final JTextField field = new JTextField();
    field.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

    });

    final PhonemListModel phonemModel = new PhonemListModel((List<Phonem>) phonesList);
    final JList phonemList = new JList(phonemModel);
    final JScrollPane spPhonemList = new JScrollPane(phonemList);
    phonemList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        // private int oldIndex = -1;
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting() == false) {
                Phonem innerPhonem = (Phonem) phonemModel.getElementAt(phonemList.getSelectedIndex());
                field.setText(field.getText() + innerPhonem.getPhonem());
            }
        }
    });
    phonemList.setCellRenderer(new PhonemListRenderer());
    list.setCellRenderer(new StatementPhonemListRenderer(face));
    list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    list.setVisibleRowCount(1);

    view.add(spPhonemList, BorderLayout.WEST);
    view.add(sp, BorderLayout.CENTER);
    view.add(field, BorderLayout.SOUTH);

    field.requestFocus();

    return view;
}

From source file:components.ListDialog.java

private ListDialog(Frame frame, Component locationComp, String labelText, String title, Object[] data,
        String initialValue, String longValue) {
    super(frame, title, true);

    //Create and initialize the buttons.
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(this);
    ////from www  . ja  va 2 s .  c om
    final JButton setButton = new JButton("Set");
    setButton.setActionCommand("Set");
    setButton.addActionListener(this);
    getRootPane().setDefaultButton(setButton);

    //main part of the dialog
    list = new JList(data) {
        //Subclass JList to workaround bug 4832765, which can cause the
        //scroll pane to not let the user easily scroll up to the beginning
        //of the list.  An alternative would be to set the unitIncrement
        //of the JScrollBar to a fixed value. You wouldn't get the nice
        //aligned scrolling, but it should work.
        public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
            int row;
            if (orientation == SwingConstants.VERTICAL && direction < 0
                    && (row = getFirstVisibleIndex()) != -1) {
                Rectangle r = getCellBounds(row, row);
                if ((r.y == visibleRect.y) && (row != 0)) {
                    Point loc = r.getLocation();
                    loc.y--;
                    int prevIndex = locationToIndex(loc);
                    Rectangle prevR = getCellBounds(prevIndex, prevIndex);

                    if (prevR == null || prevR.y >= r.y) {
                        return 0;
                    }
                    return prevR.height;
                }
            }
            return super.getScrollableUnitIncrement(visibleRect, orientation, direction);
        }
    };

    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    if (longValue != null) {
        list.setPrototypeCellValue(longValue); //get extra space
    }
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    list.setVisibleRowCount(-1);
    list.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                setButton.doClick(); //emulate button click
            }
        }
    });
    JScrollPane listScroller = new JScrollPane(list);
    listScroller.setPreferredSize(new Dimension(250, 80));
    listScroller.setAlignmentX(LEFT_ALIGNMENT);

    //Create a container so that we can add a title around
    //the scroll pane.  Can't add a title directly to the
    //scroll pane because its background would be white.
    //Lay out the label and scroll pane from top to bottom.
    JPanel listPane = new JPanel();
    listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
    JLabel label = new JLabel(labelText);
    label.setLabelFor(list);
    listPane.add(label);
    listPane.add(Box.createRigidArea(new Dimension(0, 5)));
    listPane.add(listScroller);
    listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    //Lay out the buttons from left to right.
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    buttonPane.add(Box.createHorizontalGlue());
    buttonPane.add(cancelButton);
    buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPane.add(setButton);

    //Put everything together, using the content pane's BorderLayout.
    Container contentPane = getContentPane();
    contentPane.add(listPane, BorderLayout.CENTER);
    contentPane.add(buttonPane, BorderLayout.PAGE_END);

    //Initialize values.
    setValue(initialValue);
    pack();
    setLocationRelativeTo(locationComp);
}

From source file:org.pdfsam.guiclient.commons.panels.JVisualPdfPageSelectionPanel.java

/**
 * panel initialization//from  w ww  . j  av a 2s  .  co m
 */
private void init() {
    setLayout(new GridBagLayout());

    thumbnailList.setDrawDeletedItems(drawDeletedItems);
    if (dndSupport == DND_SUPPORT_FILES) {
        thumbnailList.setTransferHandler(new VisualListExportTransferHandler(pdfLoader));
    } else if (dndSupport == DND_SUPPORT_JAVAOBJECTS) {
        thumbnailList.setTransferHandler(new VisualListTransferHandler());
    } else if (dndSupport == DND_SUPPORT_FILES_AND_JAVAOBJECTS) {
        thumbnailList.setTransferHandler(new VisualListTransferHandler(pdfLoader));
    } else {
        thumbnailList.setTransferHandler(new VisualListExportTransferHandler(null));
    }
    thumbnailList.setDragEnabled(true);
    thumbnailList.setDropMode(DropMode.INSERT);
    pagesWorker = new PagesWorker(thumbnailList);
    thumbnailList.addKeyListener(new VisualPdfSelectionKeyAdapter(pagesWorker));
    thumbnailList.addMouseListener(new PageOpenerMouseAdapter(thumbnailList));

    if (showButtonPanel) {
        initButtonPanel(pagesWorker);
        initKeyListener();
    }

    //JList orientation
    if (HORIZONTAL_ORIENTATION == orientation) {
        thumbnailList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    } else {
        if (wrap) {
            thumbnailList.setLayoutOrientation(JList.VERTICAL_WRAP);
        }
    }

    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.LINE_AXIS));
    topPanel.setPreferredSize(new Dimension(400, 30));

    pdfSelectionActionListener = new VisualPdfSelectionActionListener(this, pdfLoader);
    if (topPanelStyle >= STYLE_TOP_PANEL_FULL) {
        //load button
        loadFileButton.setMargin(new Insets(1, 1, 1, 1));
        loadFileButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Open"));
        loadFileButton.setPreferredSize(new Dimension(100, 30));
        loadFileButton
                .setToolTipText(GettextResource.gettext(config.getI18nResourceBundle(), "Load a pdf document"));
        loadFileButton.setIcon(new ImageIcon(this.getClass().getResource("/images/add.png")));
        loadFileButton.addKeyListener(new EnterDoClickListener(loadFileButton));
        loadFileButton.setAlignmentX(Component.CENTER_ALIGNMENT);
        loadFileButton.setAlignmentY(Component.CENTER_ALIGNMENT);
        loadFileButton.setActionCommand(VisualPdfSelectionActionListener.ADD);
        loadFileButton.addActionListener(pdfSelectionActionListener);
    }
    documentProperties.setIcon(new ImageIcon(this.getClass().getResource("/images/info.png")));
    documentProperties.setVisible(false);

    if (topPanelStyle >= STYLE_TOP_PANEL_MEDIUM) {
        clearButton.setMargin(new Insets(1, 1, 1, 1));
        clearButton.setMinimumSize(new Dimension(30, 30));
        clearButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Clear"));
        clearButton.setIcon(new ImageIcon(this.getClass().getResource("/images/clear.png")));
        clearButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                resetPanel();
            }
        });
    }

    zoomInButton.setMargin(new Insets(1, 1, 1, 1));
    zoomInButton.setMinimumSize(new Dimension(30, 30));
    zoomInButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Zoom in"));
    zoomInButton.setIcon(new ImageIcon(this.getClass().getResource("/images/zoomin.png")));
    zoomInButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                thumbnailList.incZoomLevel();
                zoomOutButton.setEnabled(true);
                if (thumbnailList.getCurrentZoomLevel() >= JVisualSelectionList.MAX_ZOOM_LEVEL) {
                    zoomInButton.setEnabled(false);
                }
                ((VisualListModel) thumbnailList.getModel()).elementsChanged();
            } catch (Exception ex) {
                log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error setting zoom level."),
                        ex);
            }
        }
    });

    zoomOutButton.setMargin(new Insets(1, 1, 1, 1));
    zoomOutButton.setMinimumSize(new Dimension(30, 30));
    zoomOutButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Zoom out"));
    zoomOutButton.setIcon(new ImageIcon(this.getClass().getResource("/images/zoomout.png")));
    zoomOutButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                thumbnailList.deincZoomLevel();
                zoomInButton.setEnabled(true);
                if (thumbnailList.getCurrentZoomLevel() <= JVisualSelectionList.MIN_ZOOM_LEVEL) {
                    zoomOutButton.setEnabled(false);
                }
                ((VisualListModel) thumbnailList.getModel()).elementsChanged();
            } catch (Exception ex) {
                log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error setting zoom level."),
                        ex);
            }
        }
    });

    thumbnailList.setModel(new VisualListModel());
    thumbnailList.setCellRenderer(new VisualListRenderer());
    thumbnailList.setVisibleRowCount(-1);
    thumbnailList.setSelectionMode(selectionType);
    JScrollPane listScroller = new JScrollPane(thumbnailList);

    //preview item   
    menuItemPreview.setIcon(new ImageIcon(this.getClass().getResource("/images/preview-viewer.png")));
    menuItemPreview.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Preview"));
    menuItemPreview.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            int[] selection = thumbnailList.getSelectedIndices();
            if (selection != null && selection.length == 1) {
                VisualPageListItem item = (VisualPageListItem) thumbnailList.getModel()
                        .getElementAt(selection[0]);
                PagePreviewOpener.getInstance().openPreview(item.getParentFileCanonicalPath(),
                        item.getDocumentPassword(), item.getPageNumber());
            }
        }
    });

    if (showContextMenu) {
        //popup
        final JMenuItem menuItemMoveUp = new JMenuItem();
        menuItemMoveUp.setIcon(new ImageIcon(this.getClass().getResource("/images/up.png")));
        menuItemMoveUp.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Move Up"));
        menuItemMoveUp.addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.MOVE_UP, pagesWorker));
        popupMenu.add(menuItemMoveUp);

        final JMenuItem menuItemMoveDown = new JMenuItem();
        menuItemMoveDown.setIcon(new ImageIcon(this.getClass().getResource("/images/down.png")));
        menuItemMoveDown.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Move Down"));
        menuItemMoveDown
                .addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.MOVE_DOWN, pagesWorker));
        popupMenu.add(menuItemMoveDown);

        final JMenuItem menuItemRemove = new JMenuItem();
        menuItemRemove.setIcon(new ImageIcon(this.getClass().getResource("/images/remove.png")));
        menuItemRemove.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Delete"));
        menuItemRemove.addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.REMOVE, pagesWorker));
        popupMenu.add(menuItemRemove);

        //if elements are physically deleted i don't need this item
        if (drawDeletedItems) {
            final JMenuItem menuItemUndelete = new JMenuItem();
            menuItemUndelete.setIcon(new ImageIcon(this.getClass().getResource("/images/remove.png")));
            menuItemUndelete.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Undelete"));
            menuItemUndelete
                    .addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.UNDELETE, pagesWorker));
            popupMenu.add(menuItemUndelete);
        }

        //rotate item   
        final JMenuItem menuItemRotate = new JMenuItem();
        menuItemRotate.setIcon(new ImageIcon(this.getClass().getResource("/images/clockwise.png")));
        menuItemRotate.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Rotate clockwise"));
        menuItemRotate
                .addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.ROTATE_CLOCK, pagesWorker));
        popupMenu.add(menuItemRotate);

        //rotate anticlock item   
        final JMenuItem menuItemAntiRotate = new JMenuItem();
        menuItemAntiRotate.setIcon(new ImageIcon(this.getClass().getResource("/images/anticlockwise.png")));
        menuItemAntiRotate
                .setText(GettextResource.gettext(config.getI18nResourceBundle(), "Rotate anticlockwise"));
        menuItemAntiRotate.addMouseListener(
                new VisualPdfSelectionMouseAdapter(PagesWorker.ROTATE_ANTICLOCK, pagesWorker));
        popupMenu.add(menuItemAntiRotate);

        //reverse item   
        final JMenuItem menuItemReverse = new JMenuItem();
        menuItemReverse.setIcon(new ImageIcon(this.getClass().getResource("/images/reverse.png")));
        menuItemReverse.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Reverse"));
        menuItemReverse.addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.REVERSE, pagesWorker));
        popupMenu.add(menuItemReverse);

        enableSetOutputPathMenuItem();

        addPopupShower();
    }

    popupMenu.add(menuItemPreview);

    if (topPanelStyle >= STYLE_TOP_PANEL_FULL) {
        topPanel.add(Box.createRigidArea(new Dimension(5, 0)));
        topPanel.add(loadFileButton);
    }
    if (topPanelStyle >= STYLE_TOP_PANEL_MEDIUM) {
        topPanel.add(Box.createRigidArea(new Dimension(5, 0)));
        topPanel.add(clearButton);
    }
    topPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    topPanel.add(documentProperties);
    topPanel.add(Box.createHorizontalGlue());
    topPanel.add(zoomInButton);
    topPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    topPanel.add(zoomOutButton);

    GridBagConstraints topConstraints = new GridBagConstraints();
    topConstraints.fill = GridBagConstraints.BOTH;
    topConstraints.gridx = 0;
    topConstraints.gridy = 0;
    topConstraints.gridwidth = 3;
    topConstraints.gridheight = 1;
    topConstraints.insets = new Insets(5, 5, 5, 5);
    topConstraints.weightx = 1.0;
    topConstraints.weighty = 0.0;
    if (topPanelStyle > STYLE_TOP_PANEL_HIDE) {
        add(topPanel, topConstraints);
    }

    GridBagConstraints thumbConstraints = new GridBagConstraints();
    thumbConstraints.fill = GridBagConstraints.BOTH;
    thumbConstraints.gridx = 0;
    thumbConstraints.gridy = 1;
    thumbConstraints.gridwidth = (showButtonPanel ? 2 : 3);
    thumbConstraints.gridheight = 2;
    thumbConstraints.insets = new Insets(5, 5, 5, 5);
    thumbConstraints.weightx = 1.0;
    thumbConstraints.weighty = 1.0;
    add(listScroller, thumbConstraints);

    if (showButtonPanel) {
        GridBagConstraints buttonsConstraints = new GridBagConstraints();
        buttonsConstraints.fill = GridBagConstraints.BOTH;
        buttonsConstraints.gridx = 2;
        buttonsConstraints.gridy = 1;
        buttonsConstraints.gridwidth = 1;
        buttonsConstraints.gridheight = 2;
        buttonsConstraints.insets = new Insets(5, 5, 5, 5);
        buttonsConstraints.weightx = 0.0;
        buttonsConstraints.weighty = 1.0;
        add(buttonPanel, buttonsConstraints);
    }
}