List of usage examples for javax.swing JScrollPane getViewport
public JViewport getViewport()
JViewport
. From source file:Main.java
public void setView(JScrollPane scroll, Component comp) { JViewport view = scroll.getViewport(); Point p = comp.getLocation(); view.setViewPosition(p);/*from ww w .j a v a 2 s . co m*/ }
From source file:Main.java
public Main() { JPanel buttonPanel = new JPanel(); buttonPanel.add(new JButton("Foo")); buttonPanel.add(Box.createHorizontalStrut(10)); buttonPanel.add(new JButton("Bar")); String[] columnNames = { "Mon", "Tues", "Wed" }; DefaultTableModel model = new DefaultTableModel(columnNames, 25); JTable table = new JTable(model); JScrollPane scrollPane = new JScrollPane(table); scrollPane.getViewport().setPreferredSize(table.getPreferredSize()); JLabel southLabel = new JLabel("OK!"); southLabel.setForeground(Color.white); JPanel southPanel = new JPanel(); southPanel.add(southLabel);//from w w w .j a v a2s .c o m setLayout(new BorderLayout(5, 5)); add(buttonPanel, BorderLayout.NORTH); add(scrollPane, BorderLayout.CENTER); add(southPanel, BorderLayout.SOUTH); }
From source file:RTFView.java
public RTFView() { setTitle("RTF Text Application"); setSize(400, 240);// w w w . j a v a 2 s . co m setBackground(Color.gray); getContentPane().setLayout(new BorderLayout()); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); getContentPane().add(topPanel, BorderLayout.CENTER); // Create an RTF editor window RTFEditorKit rtf = new RTFEditorKit(); JEditorPane editor = new JEditorPane(); editor.setEditorKit(rtf); editor.setBackground(Color.white); // This text could be big so add a scroll pane JScrollPane scroller = new JScrollPane(); scroller.getViewport().add(editor); topPanel.add(scroller, BorderLayout.CENTER); // Load an RTF file into the editor try { FileInputStream fi = new FileInputStream("test.rtf"); rtf.read(fi, editor.getDocument(), 0); } catch (FileNotFoundException e) { System.out.println("File not found"); } catch (IOException e) { System.out.println("I/O error"); } catch (BadLocationException e) { } }
From source file:Main.java
public TestPane() { setLayout(new BorderLayout()); JPanel top = new JPanel(new GridBagLayout()); top.setOpaque(false);// ww w . ja v a 2 s .com top.add(new JLabel("OK")); JScrollPane sp = new JScrollPane(); sp.setOpaque(false); sp.getViewport().setOpaque(false); sp.setViewportView(top); add(sp); }
From source file:Main.java
public Main(File dir) { setLayout(new BorderLayout()); JTree tree = new JTree(addNodes(null, dir)); tree.addTreeSelectionListener(e -> { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent(); System.out.println("You selected " + node); });//from w w w . jav a2 s .c o m JScrollPane scrollpane = new JScrollPane(); scrollpane.getViewport().add(tree); add(BorderLayout.CENTER, scrollpane); }
From source file:MainClass.java
protected void configureEnclosingScrollPane() { Container container = getParent(); if (container instanceof JViewport) { Container viewParent = container.getParent(); if (viewParent instanceof JScrollPane) { JScrollPane scrollPane = (JScrollPane) viewParent; JViewport viewport = scrollPane.getViewport(); if (viewport == null || viewport.getView() != this) { return; }//from w w w . ja v a 2s. c o m scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder")); } } }
From source file:Main.java
public FileTree(File dir) { setLayout(new BorderLayout()); JTree tree = new JTree(addNodes(null, dir)); tree.addTreeSelectionListener(e -> { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent(); System.out.println("You selected " + node); });// w ww . j a v a 2 s . c o m DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); JScrollPane scrollpane = new JScrollPane(); scrollpane.getViewport().add(tree); add(BorderLayout.CENTER, scrollpane); }
From source file:MainClass.java
public MainClass(File dir) { setLayout(new BorderLayout()); JTree tree = new JTree(addNodes(null, dir)); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent(); System.out.println("You selected " + node); }/*www. j ava2s.c om*/ }); JScrollPane scrollpane = new JScrollPane(); scrollpane.getViewport().add(tree); add(BorderLayout.CENTER, scrollpane); }
From source file:Main.java
public Main() { super("Swing List with Tab Renenderer"); setSize(500, 240);//from w w w . j ava 2 s . com String[] items = { "cloumn 1\t column 2\t Column 3", "cloumn 1\t column 2\t Column 3" }; list = new JList(items); TabListCellRenderer renderer = new TabListCellRenderer(); list.setCellRenderer(renderer); JScrollPane scrollPane = new JScrollPane(); scrollPane.getViewport().add(list); getContentPane().add(scrollPane, BorderLayout.CENTER); WindowListener exitEvent = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(exitEvent); setVisible(true); }
From source file:TabRenendererList.java
public TabRenendererList() { super("Swing List with Tab Renenderer"); setSize(500, 240);/*from w w w. j a v a 2 s . c o m*/ String[] items = { "cloumn 1\t column 2\t Column 3", "cloumn 1\t column 2\t Column 3" }; list = new JList(items); TabListCellRenderer renderer = new TabListCellRenderer(); list.setCellRenderer(renderer); JScrollPane scrollPane = new JScrollPane(); scrollPane.getViewport().add(list); getContentPane().add(scrollPane, BorderLayout.CENTER); WindowListener exitEvent = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(exitEvent); setVisible(true); }