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);/*w w w . j a v a 2s. c o m*/ jlist1.setVisibleRowCount(4); JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); ListSelectionListener[] lis = jlist1.getListSelectionListeners(); 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);/*ww w .ja va2 s . c om*/ jlist1.setVisibleRowCount(4); JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); boolean b = jlist1.getDragEnabled(); 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 w w . ja v a2s .c om*/ jlist1.setVisibleRowCount(4); JScrollPane scrollPane1 = new JScrollPane(jlist1); frame.add(scrollPane1, BorderLayout.NORTH); int s = jlist1.getFixedCellHeight(); frame.setSize(300, 350); 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 ww .java 2s . c o m JEditorPane editorPane = new JEditorPane("http://www.java2s.com"); editorPane.setEditable(false); URL url = editorPane.getPage(); 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) { Integer[][] data = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; String[] cols = { "A", "B", "C" }; JTable table = new JTable(data, cols); JTableHeader header = table.getTableHeader(); header.setBackground(Color.black); header.setForeground(Color.yellow); JOptionPane.showMessageDialog(null, new JScrollPane(table)); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(); Box box = Box.createVerticalBox(); for (int i = 0; i < 100; i++) { box.add(new JLabel("Hello!")); }/*from w w w . j ava2 s . c om*/ panel.add(box); JTabbedPane tab = new JTabbedPane(); JScrollPane scroll = new JScrollPane(panel); scroll.setPreferredSize(new Dimension(300, 300)); tab.add(scroll, "Panel 1"); JOptionPane.showMessageDialog(null, tab, "Test Tabbed", JOptionPane.PLAIN_MESSAGE); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout()); gui.setBorder(new EmptyBorder(2, 3, 2, 3)); JPanel textPanel = new JPanel(new BorderLayout(5, 5)); textPanel.add(new JScrollPane(new JTextArea("Top Text", 3, 20)), BorderLayout.PAGE_START); textPanel.add(new JScrollPane(new JTextArea("Main Text", 10, 10))); gui.add(textPanel, BorderLayout.CENTER); JPanel buttonCenter = new JPanel(new GridBagLayout()); buttonCenter.setBorder(new EmptyBorder(5, 5, 5, 5)); JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 5, 5)); for (int ii = 1; ii < 6; ii++) { buttonPanel.add(new JButton("Button " + ii)); }//from ww w . j a va2 s. co m buttonCenter.add(buttonPanel); gui.add(buttonCenter, BorderLayout.LINE_END); JFrame f = new JFrame("Demo"); f.add(gui); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setLocationByPlatform(true); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H" }; 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, BorderLayout.CENTER); 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 selectionValues[] = list.getSelectedValues(); for (int i = 0, n = selections.length; i < n; i++) { if (i == 0) { System.out.println(" Selections: "); }//from w ww . ja v a2s . c o m System.out.println(selections[i] + "/" + selectionValues[i] + " "); } } } }; jlist.addListSelectionListener(listSelectionListener); frame.setSize(350, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws UnsupportedEncodingException { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); JPanel buttons = new JPanel(); JScrollPane pane = new JScrollPane(buttons); pane.getViewport().addChangeListener(e -> { System.out.println("Change in " + e.getSource()); System.out.println("Vertical visible? " + pane.getVerticalScrollBar().isVisible()); System.out.println("Horizontal visible? " + pane.getHorizontalScrollBar().isVisible()); });/*from ww w . j ava 2 s . co m*/ panel.add(pane); frame.setContentPane(panel); frame.setSize(300, 200); frame.setVisible(true); SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { for (int i = 0; i < 10; i++) { Thread.sleep(800); buttons.add(new JButton("Hello " + i)); buttons.revalidate(); } return null; } }; worker.execute(); }
From source file:TableModelListenerDemo.java
public static void main(String args[]) { final Object rowData[][] = { { "1", "one", "I" }, { "2", "two", "II" }, { "3", "three", "III" } }; final String columnNames[] = { "#", "English", "Roman" }; final JTable table = new JTable(rowData, columnNames); JScrollPane scrollPane = new JScrollPane(table); table.getModel().addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { System.out.println(e); }// w ww . j a v a2 s . c om }); table.setValueAt("", 0, 0); JFrame frame = new JFrame("Resizing Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }