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(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DefaultListModel model = new DefaultListModel(); model.ensureCapacity(1000);/*ww w. ja v a2 s. co m*/ for (int i = 0; i < 100; i++) { for (int j = 0; j < 5; j++) { model.addElement(labels[j]); } } Object[] objs = new Object[10]; System.out.println(model.elementAt(1)); 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(final String args[]) { final String labels[] = { "A", "B", "C", "D", "E" }; final DefaultComboBoxModel model = new DefaultComboBoxModel(labels); JFrame frame = new JFrame("Shared Data"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox comboBox1 = new JComboBox(model); comboBox1.setMaximumRowCount(5);/*from w w w . java 2 s.c o m*/ comboBox1.setEditable(true); frame.add(comboBox1, BorderLayout.NORTH); JList jlist = new JList(model); JScrollPane scrollPane = new JScrollPane(jlist); frame.add(scrollPane, BorderLayout.CENTER); JButton button = new JButton("Add"); frame.add(button, BorderLayout.SOUTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { model.addElement("a"); } }; button.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(200, 200);/*from w w w. jav a 2 s .c o m*/ f.getContentPane().setLayout(new BorderLayout()); JTextPane jtp = new JTextPane(); jtp.setEditorKit(new WrapEditorKit()); JScrollPane jsp = new JScrollPane(jtp); jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); f.getContentPane().add(jsp, BorderLayout.CENTER); jtp.setText("thisIsATestThisisAtestthisIsATestThisisAtestthisIsATestThisisAtest"); f.setVisible(true); }
From source file:Main.java
public static void main(final String args[]) { final String labels[] = { "A", "B", "C", "D", "E" }; final DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>(labels); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox<String> comboBox1 = new JComboBox<String>(model); comboBox1.setMaximumRowCount(5);// w w w . ja va 2 s .c o m comboBox1.setEditable(true); frame.add(comboBox1, BorderLayout.NORTH); JList<String> jlist = new JList<String>(model); JScrollPane scrollPane = new JScrollPane(jlist); frame.add(scrollPane, BorderLayout.CENTER); JButton button = new JButton("Add"); frame.add(button, BorderLayout.SOUTH); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { model.addElement("a"); } }; button.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:JTextAreaBackgroundSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Background Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final ImageIcon imageIcon = new ImageIcon("yourFile.gif"); JTextArea textArea = new JTextArea() { Image image = imageIcon.getImage(); Image grayImage = GrayFilter.createDisabledImage(image); {/* w ww .j av a2s .c o m*/ setOpaque(false); } public void paint(Graphics g) { g.drawImage(grayImage, 0, 0, this); super.paint(g); } }; JScrollPane scrollPane = new JScrollPane(textArea); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(250, 250); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String argv[]) { ColorPane pane = new ColorPane(); for (int n = 1; n <= 400; n += 1) { if (isPrime(n)) { pane.append(Color.red, String.valueOf(n) + ' '); } else if (isPerfectSquare(n)) { pane.append(Color.blue, String.valueOf(n) + ' '); } else {// w w w . j a va 2 s. c o m pane.append(Color.black, String.valueOf(n) + ' '); } } JFrame f = new JFrame("ColorPane example"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setContentPane(new JScrollPane(pane)); f.setSize(600, 400); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String[] headers = { "column 1", "column 2", "column 3", "column 4" }; int cols = 4; int rows = 6; String[][] data = new String[rows][cols]; for (int row = 0; row < rows; row++) { for (int col = 0; col < cols; col++) { data[row][col] = "item " + (row * cols + col + 1); }//w w w.j a va2 s .c o m } JTable table = new JTable(data, headers); DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) table.getDefaultRenderer(String.class); renderer.setHorizontalAlignment(JLabel.RIGHT); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(table)); f.setSize(400, 400); f.setLocation(200, 200); f.setVisible(true); }
From source file:ToolBarSample.java
public static void main(final String args[]) { JFrame frame = new JFrame("JToolBar Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JToolBar toolbar = new JToolBar(); toolbar.setRollover(true);/* w ww. j a v a 2s . c om*/ JButton button = new JButton("button"); toolbar.add(button); toolbar.addSeparator(); toolbar.add(new JButton("button 2")); toolbar.add(new JComboBox(new String[] { "A", "B", "C" })); Container contentPane = frame.getContentPane(); contentPane.add(toolbar, BorderLayout.NORTH); JTextArea textArea = new JTextArea(); JScrollPane pane = new JScrollPane(textArea); contentPane.add(pane, BorderLayout.CENTER); frame.setSize(350, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Background Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final ImageIcon imageIcon = new ImageIcon("draft.gif"); JTextArea textArea = new JTextArea() { Image image = imageIcon.getImage(); Image grayImage = GrayFilter.createDisabledImage(image); {/*from w w w . j a va2 s . co m*/ setOpaque(false); } public void paint(Graphics g) { g.drawImage(grayImage, 0, 0, this); super.paint(g); } }; JScrollPane scrollPane = new JScrollPane(textArea); Container content = frame.getContentPane(); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(250, 250); frame.setVisible(true); }
From source file:TreeNodeRemove.java
public static void main(String[] argv) { Vector<String> v = new Vector<String>(); v.add("a");//from w w w .j av a 2 s. com v.add("b"); v.add("c"); JTree tree = new JTree(v); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); int startRow = 0; String prefix = "b"; TreePath path = tree.getNextMatch(prefix, startRow, Position.Bias.Forward); MutableTreeNode node = (MutableTreeNode) path.getLastPathComponent(); model.removeNodeFromParent(node); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(tree)); frame.setSize(380, 320); frame.setLocationRelativeTo(null); frame.setVisible(true); }