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) throws Exception { String[] columns = { "Name", "Age" }; Object[][] content = { { "R", new Integer(24) }, { "A", new Integer(25) }, { "J", new Integer(30) }, { "A", new Integer(32) }, { "S", new Integer(27) } }; JTable table = new JTable(content, columns); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel jPanel = new JPanel(new GridLayout(2, 0)); jPanel.setOpaque(true);/*from www . j a v a 2s . co m*/ table.setPreferredScrollableViewportSize(new Dimension(500, 70)); jPanel.add(new JScrollPane(table)); /* Add the panel to the JFrame */ frame.add(jPanel); /* Display the JFrame window */ frame.pack(); frame.setVisible(true); table.print(); }
From source file:Main.java
public static void main(final String args[]) { String labels[] = { "A", "B", "C", "D", "E" }; JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultListModel model = new DefaultListModel(); model.ensureCapacity(1000);// ww w . j a va 2s.c om for (int j = 0; j < 5; j++) { model.addElement(labels[j]); } model.trimToSize(); JList jlist2 = new JList(model); jlist2.setVisibleRowCount(4); jlist2.setFixedCellHeight(12); jlist2.setFixedCellWidth(200); JScrollPane scrollPane2 = new JScrollPane(jlist2); frame.add(scrollPane2, BorderLayout.CENTER); frame.setSize(300, 350); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { String rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } }; String headers[] = { "Upper", "Lower" }; JFrame frame = new JFrame("Label Header"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTable table = new JTable(rows, headers); JScrollPane scrollPane = new JScrollPane(table); Border headerBorder = UIManager.getBorder("TableHeader.cellBorder"); JLabel headerLabel1 = new JLabel(headers[0], JLabel.CENTER); headerLabel1.setBorder(headerBorder); JLabel headerLabel2 = new JLabel(headers[1], JLabel.CENTER); headerLabel2.setBorder(headerBorder); TableCellRenderer renderer = new JComponentTableCellRenderer(); TableColumnModel columnModel = table.getColumnModel(); TableColumn column0 = columnModel.getColumn(0); TableColumn column1 = columnModel.getColumn(1); column0.setHeaderRenderer(renderer); column0.setHeaderValue(headerLabel1); column1.setHeaderRenderer(renderer); column1.setHeaderValue(headerLabel2); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150);//from ww w . j a va 2 s .c o m frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Properties props = System.getProperties(); JTree tree = new JTree(props); JComboBox comboBox = new JComboBox(new String[] { "A", "B", "C" }); TreeCellEditor editor = new DefaultCellEditor(comboBox); tree.setEditable(true);//from ww w. j a v a2 s . co m tree.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:CornerSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Cornering Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Icon miniLogo = new ImageIcon("logo.gif"); Icon acrossLogo = new ImageIcon("logo-across.jpg"); Icon downLogo = new ImageIcon("logo-down.jpg"); Icon bookCover = new ImageIcon("puzzlebook.jpg"); JLabel logoLabel = new JLabel(miniLogo); JLabel columnLabel = new JLabel(acrossLogo); JLabel rowLabel = new JLabel(downLogo); JLabel coverLabel = new JLabel(bookCover); JScrollPane scrollPane = new JScrollPane(coverLabel); scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, logoLabel); scrollPane.setColumnHeaderView(columnLabel); scrollPane.setRowHeaderView(rowLabel); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 200);//from w ww. j ava 2 s . c o m 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 {//from w w w.j av a 2 s . com JEditorPane editorPane = new JEditorPane(new URL("http://www.java2s.com")); editorPane.setEditable(false); HyperlinkListener hyperlinkListener = new ActivatedHyperlinkListener(editorPane); editorPane.addHyperlinkListener(hyperlinkListener); 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[]) { JTextArea textArea = new JTextArea(); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); DefaultCaret caret = new DefaultCaret() { @Override/*from w w w . java 2 s . co m*/ public boolean isSelectionVisible() { return true; } }; textArea.setCaret(caret); textArea.setFont(new java.awt.Font("Miriam Fixed", 0, 13)); Color color = Color.BLUE; // textArea.setBackground(color); textArea.setSelectedTextColor(color); f.getContentPane().add(new JScrollPane(textArea)); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); int x = 5;/*from w w w . j a v a 2 s . co m*/ int y = 5; JPanel panel = new JPanel(); panel.setLayout(new GridLayout(x, y)); for (int i = 0; i < x * y; i++) { JButton button = new JButton(String.valueOf(i)); button.setPreferredSize(new Dimension(100, 100)); panel.add(button); } JPanel container = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0)); container.add(panel); JScrollPane scrollPane = new JScrollPane(container); f.getContentPane().add(scrollPane); f.pack(); f.setLocationRelativeTo(null); 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(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultListModel model = new DefaultListModel(); model.ensureCapacity(1000);/*from www . ja va 2s . c om*/ for (int j = 0; j < 5; j++) { model.addElement(labels[j]); } System.out.println(model.toString()); JList jlist2 = new JList(model); jlist2.setVisibleRowCount(4); jlist2.setFixedCellHeight(12); jlist2.setFixedCellWidth(200); JScrollPane scrollPane2 = new JScrollPane(jlist2); frame.add(scrollPane2, BorderLayout.CENTER); frame.setSize(300, 350); frame.setVisible(true); }
From source file:LazySample.java
public static void main(String args[]) { JFrame frame = new JFrame("Lazy Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Integer fifteen = new Integer(15); Object lazyArgs[] = new Object[] { Color.GREEN, Boolean.TRUE, fifteen, fifteen }; Object lazyDiamond = new UIDefaults.ProxyLazyValue("MyIcon", lazyArgs); UIManager.put("Tree.openIcon", lazyDiamond); JTree tree = new JTree(); JScrollPane scrollPane = new JScrollPane(tree); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(200, 200);/*from w w w . j a v a 2s . c o m*/ frame.setVisible(true); }