List of usage examples for javax.swing JScrollPane JScrollPane
public JScrollPane(Component view)
JScrollPane
that displays the contents of the specified component, where both horizontal and vertical scrollbars appear whenever the component's contents are larger than the view. From source file:MainClass.java
public static void main(String args[]) { JFrame f = new JFrame("JTable Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Object rows[][] = { { "A", "Name 1", "38.94" }, { "B", "Name 2", "7.70" }, { "C", "Name 3", "112.65" } }; Object columns[] = { "Symbol", "Name", "Price" }; JTable table = new JTable(rows, columns); JScrollPane scrollPane = new JScrollPane(table); f.add(scrollPane, BorderLayout.CENTER); f.setSize(300, 200);/* w ww . j a va 2 s . c om*/ f.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { final String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Selecting JList"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JList jlist = new JList(labels); JScrollPane scrollPane1 = new JScrollPane(jlist); frame.add(scrollPane1);//from w ww . j a v a 2 s. c o m ListSelectionListener listSelectionListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent listSelectionEvent) { List objs = jlist.getSelectedValuesList(); } }; jlist.addListSelectionListener(listSelectionListener); frame.setSize(350, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JEditorPane jep = new JEditorPane(); jep.setEditable(false);//from ww w . j a v a2 s . c o m try { jep.setPage("http://www.google.com"); } catch (IOException e) { jep.setContentType("text/html"); jep.setText("<html>Could not load http://www.google.com </html>"); } JScrollPane scrollPane = new JScrollPane(jep); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(scrollPane); f.setSize(512, 342); f.show(); }
From source file:MainClass.java
public static void main(final String args[]) { final String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Selecting JList"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist = new JList(labels); JScrollPane scrollPane1 = new JScrollPane(jlist); frame.add(scrollPane1);// w w w .j av a 2 s . c om ListSelectionListener listSelectionListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent listSelectionEvent) { System.out.println("First index: " + listSelectionEvent.getFirstIndex()); System.out.println(", Last index: " + listSelectionEvent.getLastIndex()); boolean adjust = listSelectionEvent.getValueIsAdjusting(); System.out.println(", Adjusting? " + adjust); if (!adjust) { JList list = (JList) listSelectionEvent.getSource(); int selections[] = list.getSelectedIndices(); Object selectedValues[] = list.getSelectedValues(); for (int i = 0, n = selections.length; i < n; i++) { if (i == 0) { System.out.println(" Selections: "); } System.out.println(selections[i] + "/" + selectedValues[i] + " "); } } } }; jlist.addListSelectionListener(listSelectionListener); frame.setSize(350, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist1 = new JList(); jlist1.setListData(labels);/*from w w w . j av a 2 s . c om*/ jlist1.setVisibleRowCount(4); JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); ListCellRenderer r = jlist1.getCellRenderer(); frame.setSize(300, 350); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] names = { "John Smith", "this is a test", "this is a test. this is a test. " }; MyCellRenderer cellRenderer = new MyCellRenderer(80); JList<String> list = new JList<>(names); list.setCellRenderer(cellRenderer);/* w w w. j av a2 s . co m*/ JScrollPane sPane = new JScrollPane(list); JPanel panel = new JPanel(); panel.add(sPane); JOptionPane.showMessageDialog(null, panel); }
From source file:MainClass.java
public static void main(final String args[]) { final String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Selecting JList"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist = new JList(labels); JScrollPane scrollPane1 = new JScrollPane(jlist); frame.add(scrollPane1);/*w w w . j ava 2 s.c o m*/ MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent mouseEvent) { JList theList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = theList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = theList.getModel().getElementAt(index); System.out.println("Double-clicked on: " + o.toString()); } } } }; jlist.addMouseListener(mouseListener); frame.setSize(350, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist1 = new JList(); jlist1.setListData(labels);//ww w.j ava 2s . com jlist1.setVisibleRowCount(4); JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); ListSelectionModel model = jlist1.getSelectionModel(); frame.setSize(300, 350); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H" }; JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList<String> jlist = new JList<>(labels); JScrollPane scrollPane1 = new JScrollPane(jlist); f.add(scrollPane1, BorderLayout.CENTER); MouseListener mouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent mouseEvent) { JList<String> theList = (JList) mouseEvent.getSource(); if (mouseEvent.getClickCount() == 2) { int index = theList.locationToIndex(mouseEvent.getPoint()); if (index >= 0) { Object o = theList.getModel().getElementAt(index); System.out.println("Double-clicked on: " + o.toString()); }//from w w w . j av a2 s . co m } } }; jlist.addMouseListener(mouseListener); f.setSize(350, 200); f.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist1 = new JList(); jlist1.setListData(labels);/*from ww w. ja va 2 s . c om*/ jlist1.setVisibleRowCount(4); JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); int s = jlist1.getFixedCellWidth(); frame.setSize(300, 350); frame.setVisible(true); }