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) { final StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append("<body><ol>"); Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); for (Font font : fonts) { String name = font.getName(); sb.append("<li style='font-family: " + name + "; font-size: 20px;'>"); sb.append(name);// ww w . j a va 2 s. com } JScrollPane sp = new JScrollPane(new JLabel(sb.toString())); Dimension d = sp.getPreferredSize(); sp.setPreferredSize(new Dimension(d.width, 150)); JOptionPane.showMessageDialog(null, sp); }
From source file:Main.java
public static void main(String[] args) { JEditorPane htmlPane = new JEditorPane(); String description = "<html><body>Hello<table border=1>" + "<tr><td><img alt='Bad' src='http://www.java2s.com/style/download.png'/></tr></td></table></body></html>"; htmlPane.setContentType("text/html"); htmlPane.setText(description);/*from w w w . j ava 2 s.c om*/ JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(htmlPane)); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { DefaultTableModel model = new DefaultTableModel(); JTable table = new JTable(model); model.addColumn("Col1"); model.addRow(new Object[] { "r1" }); model.addRow(new Object[] { "r2" }); model.addRow(new Object[] { "r3" }); // Move the first two rows to the end of the table model.moveRow(0, 1, model.getRowCount() - 2); JFrame f = new JFrame(); f.setSize(300, 300);/* w w w . j av a 2s. c o m*/ f.add(new JScrollPane(table)); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel topPanel = new JPanel(); topPanel.setPreferredSize(new Dimension(200, 200)); topPanel.setBackground(Color.WHITE); JTextArea chatArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(chatArea); JPanel mainPanel = new JPanel(new BorderLayout(5, 5)); mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); mainPanel.add(topPanel, BorderLayout.CENTER); mainPanel.add(scrollPane, BorderLayout.SOUTH); chatArea.getDocument().addDocumentListener(new DocumentListener() { @Override/*from www .j ava 2 s . co m*/ public void insertUpdate(DocumentEvent e) { updateLineCount(); } @Override public void removeUpdate(DocumentEvent e) { updateLineCount(); } @Override public void changedUpdate(DocumentEvent e) { updateLineCount(); } private void updateLineCount() { int lineCount = chatArea.getLineCount(); if (lineCount <= 4) { chatArea.setRows(lineCount); mainPanel.revalidate(); } } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(mainPanel); f.pack(); f.setVisible(true); }
From source file:UsingTreeSelectionListener.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTree tree = new JTree(); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.addTreeSelectionListener(new SelectionListener()); frame.add(new JScrollPane(tree)); frame.setSize(300, 200);/*from www . j a v a2 s .c om*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultTableModel model = new DefaultTableModel(); model.setColumnIdentifiers(new Object[] { "Column 1", "Column 2", "Column 3" }); JTable table = new JTable(model); for (int count = 0; count < 3; count++) { model.insertRow(count, new Object[] { count, "name", "age" }); }/* w ww. j a v a 2 s . c om*/ table.setRowHeight(1, 30); frame.add(new JScrollPane(table)); frame.setLocationByPlatform(true); frame.pack(); frame.setVisible(true); }
From source file:DnDBetweenJTextAreaAndJTextFieldDemo.java
public static void main(String[] args) { JFrame frame = new JFrame("Drag and Drop Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(new JPanel()); JTextField textField = new JTextField(25); textField.setText("www.java2s.com"); frame.add(textField);/* w w w. jav a2 s.c om*/ JTextArea textArea = new JTextArea(4, 25); textArea.setText("Demonstrating\ndrag and drop"); frame.getContentPane().add(new JScrollPane(textArea)); textArea.setDragEnabled(true); textField.setDragEnabled(true); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel panel = new JPanel(new GridBagLayout()); for (int i = 0; i < 25; i++) { JTextField field = new JTextField("Field " + i, 20); GridBagConstraints constraints = new GridBagConstraints(); constraints.gridy = i;/*from w w w .ja va 2 s. co m*/ panel.add(field, constraints); } JScrollPane scrollPane = new JScrollPane(panel); JButton removeButton = new JButton("Remove Field"); removeButton.addActionListener(e -> { if (panel.getComponentCount() >= 1) { panel.remove(panel.getComponentCount() - 1); scrollPane.revalidate(); scrollPane.repaint(); } }); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(640, 480); f.setLocation(200, 200); f.getContentPane().add(scrollPane); f.getContentPane().add(removeButton, BorderLayout.SOUTH); f.setVisible(true); }
From source file:ModifyModelSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Modifying Model"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Fill model final DefaultListModel model = new DefaultListModel(); for (int i = 0, n = labels.length; i < n; i++) { model.addElement(labels[i]);//from w w w .ja v a2 s . com } JList jlist = new JList(model); JScrollPane scrollPane1 = new JScrollPane(jlist); frame.add(scrollPane1, BorderLayout.CENTER); frame.setSize(640, 300); frame.setVisible(true); }
From source file:LoadingHTMLDocuments.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Tab Attributes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JEditorPane editorPane = new JEditorPane(); editorPane.setEditorKit(new HTMLEditorKit()); String filename = "yourFile.htm"; FileReader reader = new FileReader(filename); editorPane.read(reader, filename);/*w w w .java2 s . c o m*/ JScrollPane scrollPane = new JScrollPane(editorPane); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }