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(String args[]) { String ITEMS[] = { "Black", "Blue", "Green", "Orange", "Purple", "Red", "White" }; JList jList = new JList(ITEMS); jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(jList); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); JCheckBox chkEnable = new JCheckBox("Enable", true); chkEnable.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { jList.setEnabled(chkEnable.isSelected()); }//ww w . j a va 2s . c o m }); JFrame f = new JFrame("Colors"); Container contentPane = f.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(scroll, BorderLayout.CENTER); contentPane.add(chkEnable, BorderLayout.NORTH); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(180, 220); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame f = new JFrame("JEditorPane Sample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container content = f.getContentPane(); JEditorPane editor = new JEditorPane("text/html", "<H3>Help</H3><center><IMG src=file:///c:/a.jpg></center><li>One<li><i>Two</i><li><u>Three</u>"); editor.setEditable(false);// ww w .j a va 2s .c o m JScrollPane scrollPane = new JScrollPane(editor); content.add(scrollPane, BorderLayout.CENTER); f.setSize(300, 200); f.setVisible(true); }
From source file:MainClass.java
public static void main(final String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } }; final Object headers[] = { "English", "Digit" }; JFrame frame = new JFrame("Scrollless Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); JViewport viewport = new JViewport(); viewport.setView(table);//from w ww .ja va2 s . c o m scrollPane.setColumnHeaderView(new JLabel("table header here")); scrollPane.setRowHeaderView(viewport); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JProgressBar pb = new JProgressBar(); JTextArea ta = new JTextArea(10, 20); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(ta)); frame.add(pb, BorderLayout.SOUTH); frame.pack();// www . j av a 2 s . c om frame.setVisible(true); new BackgroundWorker(ta, pb).execute(); }
From source file:JScrollPaneHeadersandCorners.java
public static void main(String args[]) { final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" }, { "four", "4" }, };//from w ww . j a v a2 s . c o m final Object headers[] = { "English", "#" }; JFrame frame = new JFrame("Table Printing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new JButton("...")); frame.setSize(300, 150); frame.setVisible(true); }
From source file:JListTest.java
public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame = new JFrame("JList Test"); frame.setLayout(new FlowLayout()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String[] selections = { "green", "red", "orange", "dark blue" }; JList list = new JList(selections); list.setSelectedIndex(1);// w w w .j a va 2 s .c o m System.out.println(list.getSelectedValue()); frame.add(new JScrollPane(list)); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Sizing Samples"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultListModel model = new DefaultListModel(); model.ensureCapacity(100);//from w w w . j a v a 2 s .c o m for (int i = 0; i < 100; i++) { model.addElement(Integer.toString(i)); } JList jlist2 = new JList(model); JScrollPane scrollPane2 = new JScrollPane(jlist2); frame.add(scrollPane2, BorderLayout.CENTER); frame.setSize(300, 350); frame.setVisible(true); jlist2.ensureIndexIsVisible(50); }
From source file:JListSelectionModeAnchor.java
public static void main(String args[]) { JFrame frame = new JFrame("Modifying Model"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JList jlist = new JList(new String[] { "A", "B", "C" }); jlist.getSelectionModel().setAnchorSelectionIndex(0); jlist.getSelectionModel().setLeadSelectionIndex(2); JScrollPane scrollPane1 = new JScrollPane(jlist); frame.add(scrollPane1, BorderLayout.CENTER); frame.setSize(640, 300);/* www . ja v a2s . c om*/ frame.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { JFrame frame = new JFrame("EditorPane Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try {/* w w w . j a v a2s . c o m*/ JEditorPane editorPane = new JEditorPane("http://www.java2s.com"); editorPane.setEditable(false); AccessibleContext context = editorPane.getAccessibleContext(); JScrollPane scrollPane = new JScrollPane(editorPane); frame.add(scrollPane); } catch (IOException e) { System.err.println("Unable to load: " + e); } frame.setSize(640, 480); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { int MAX_CELLS = 30; DefaultListModel<String> listModel = new DefaultListModel<>(); JList<String> myList = new JList<>(listModel); myList.setVisibleRowCount(8);//from w ww.j a v a 2 s.com for (int i = 0; i < MAX_CELLS; i++) { listModel.addElement("label " + i); } JTabbedPane jTabbedPane = new JTabbedPane(); jTabbedPane.add("Test", new JScrollPane(myList)); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(jTabbedPane); frame.pack(); frame.setVisible(true); }