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: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 2s.c o m*/ jlist1.setVisibleRowCount(4); JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); jlist1.getLeadSelectionIndex(); frame.setSize(300, 350); 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 ww. j av a 2 s. c o m jlist1.setVisibleRowCount(4); JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); jlist1.setSelectedIndices(new int[] { 1, 2 }); frame.setSize(300, 350); 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(labels); jlist1.setVisibleRowCount(4);/*from w w w. j ava2s . co m*/ JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); jlist1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); frame.setSize(300, 350); frame.setVisible(true); }
From source file:DualSample.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; JFrame f = new JFrame("Sample Components"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList list = new JList(labels); JScrollPane scrollPane = new JScrollPane(list); JComboBox comboBox = new JComboBox(labels); comboBox.setMaximumRowCount(4);/*ww w . j a v a2s . co m*/ Container contentPane = f.getContentPane(); contentPane.add(comboBox, BorderLayout.NORTH); contentPane.add(scrollPane, BorderLayout.CENTER); f.setSize(300, 200); 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);//ww w . j a va 2s . com ListSelectionListener listSelectionListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent listSelectionEvent) { System.out.println(jlist.getSelectedValue()); } }; jlist.addListSelectionListener(listSelectionListener); frame.setSize(350, 200); frame.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 w w .j a va 2 s . com ListSelectionListener listSelectionListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent listSelectionEvent) { Object[] objs = jlist.getSelectedValues(); } }; jlist.addListSelectionListener(listSelectionListener); frame.setSize(350, 200); frame.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);//w ww. ja v a2 s. c om ListSelectionListener listSelectionListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent listSelectionEvent) { System.out.println(jlist.getSelectedIndex()); } }; jlist.addListSelectionListener(listSelectionListener); frame.setSize(350, 200); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame f = new JFrame("JEditorPane Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JEditorPane editor = new JEditorPane("text/html", "<H3>Help</H3><center>www.java2s.com</center><li>One<li><i>Two</i><li><u>Three</u>"); editor.setEditable(false);//from w w w.j av a2 s. co m JScrollPane scrollPane = new JScrollPane(editor); f.add(scrollPane, BorderLayout.CENTER); f.setSize(300, 200); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextArea comp = new JTextArea(); String actionName = "Lowercase"; JFrame f = new JFrame(); f.add(new JScrollPane(comp)); f.setSize(300, 300);// ww w .j av a 2s . c om f.setVisible(true); comp.getInputMap().put(KeyStroke.getKeyStroke("F2"), actionName); comp.getActionMap().put(actionName, new TextAction(actionName) { public void actionPerformed(ActionEvent evt) { JTextComponent comp = getTextComponent(evt); if (comp.getSelectionStart() == comp.getSelectionEnd()) { if (comp.getCaretPosition() < comp.getDocument().getLength()) { try { int pos = comp.getCaretPosition(); Document doc = comp.getDocument(); String str = doc.getText(pos, 1).toLowerCase(); doc.remove(pos, 1); doc.insertString(pos, str, null); comp.moveCaretPosition(pos + 1); } catch (Exception e) { System.out.println(); } } } else { int s = comp.getSelectionStart(); int e = comp.getSelectionEnd(); comp.replaceSelection(comp.getSelectedText().toLowerCase()); comp.select(s, e); } } }); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Vector<String> data = new Vector<String>(); for (int i = 1; i < 100; i++) { data.add("Entry " + i); }//ww w.j a v a 2 s . co m JList<String> list = new JList<>(data); list.setVisibleRowCount(8); JScrollPane scrollPane = new JScrollPane(list); frame.add(scrollPane); frame.pack(); frame.setVisible(true); }