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:JScrollPaneToTopAction.java
public static void main(String args[]) { JFrame frame = new JFrame("Tabbed Pane Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Label"); label.setPreferredSize(new Dimension(1000, 1000)); JScrollPane jScrollPane = new JScrollPane(label); JButton bn = new JButton("Move"); bn.addActionListener(new JScrollPaneToTopAction(jScrollPane)); frame.add(bn, BorderLayout.SOUTH); frame.add(jScrollPane, BorderLayout.CENTER); frame.setSize(400, 150);/*from www . j av a2 s.c o m*/ frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { JTree tree = new JTree(); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); int treeSelectedRows[] = { 3, 1 }; tree.setSelectionRows(treeSelectedRows); TreeSelectionListener treeSelectionListener = new TreeSelectionListener() { @Override//from w ww .j a va 2 s . com public void valueChanged(TreeSelectionEvent treeSelectionEvent) { JTree treeSource = (JTree) treeSelectionEvent.getSource(); System.out.println("Min: " + treeSource.getMinSelectionRow()); System.out.println("Max: " + treeSource.getMaxSelectionRow()); System.out.println("Lead: " + treeSource.getLeadSelectionRow()); System.out.println("Row: " + treeSource.getSelectionRows()[0]); } }; tree.addTreeSelectionListener(treeSelectionListener); JFrame frame = new JFrame("JTree With Multi-Discontiguous selection"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(tree)); frame.setPreferredSize(new Dimension(380, 320)); frame.setLocation(150, 150); frame.pack(); frame.setVisible(true); }
From source file:TabSample.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("Tab Attributes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument document = new DefaultStyledDocument(); //TabStop.ALIGN_CENTER, TabStop.ALIGN_DECIMAL,TabStop.ALIGN_LEFT, TabStop.ALIGN_RIGHT //"\tBAR\n", "\tCENTER\n", "\t3.14159265\n", "\tLEFT\n", "\tRIGHT\n" }; SimpleAttributeSet attributes = new SimpleAttributeSet(); TabStop tabstop = new TabStop(150, TabStop.ALIGN_BAR, TabStop.LEAD_DOTS); int position = document.getLength(); document.insertString(position, "TabStop.ALIGN_BAR", null); TabSet tabset = new TabSet(new TabStop[] { tabstop }); StyleConstants.setTabSet(attributes, tabset); document.setParagraphAttributes(position, 1, attributes, false); JTextPane textPane = new JTextPane(document); textPane.setEditable(false);//w ww.ja va 2s .c o m JScrollPane scrollPane = new JScrollPane(textPane); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Drag Image"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Icon icon = new ImageIcon("image.jpg"); JLabel label = new JLabel(icon); label.setTransferHandler(new ImageSelection()); MouseListener listener = new MouseAdapter() { public void mousePressed(MouseEvent me) { JComponent comp = (JComponent) me.getSource(); TransferHandler handler = comp.getTransferHandler(); handler.exportAsDrag(comp, me, TransferHandler.COPY); }/*from w w w. ja v a2 s.c o m*/ }; label.addMouseListener(listener); frame.add(new JScrollPane(label), BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:SimpleAttributeBoldItalicColor.java
public static void main(String args[]) { JFrame frame = new JFrame("Simple Attributes"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument document = new DefaultStyledDocument(); SimpleAttributeSet attributes = new SimpleAttributeSet(); attributes = new SimpleAttributeSet(); attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.FALSE); attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.FALSE); attributes.addAttribute(StyleConstants.CharacterConstants.Foreground, Color.LIGHT_GRAY); try {// w ww.ja v a 2 s.c o m document.insertString(document.getLength(), " Bold, Italic and light gray color", attributes); } catch (BadLocationException badLocationException) { System.err.println("Bad insert"); } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }
From source file:KeymapExample.java
public static void main(String[] args) { JTextArea area = new JTextArea(6, 32); Keymap parent = area.getKeymap(); Keymap newmap = JTextComponent.addKeymap("KeymapExampleMap", parent); KeyStroke u = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK); Action actionU = new UpWord(); newmap.addActionForKeyStroke(u, actionU); Action actionList[] = area.getActions(); Hashtable lookup = new Hashtable(); for (int j = 0; j < actionList.length; j += 1) lookup.put(actionList[j].getValue(Action.NAME), actionList[j]); KeyStroke L = KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK); Action actionL = (Action) lookup.get(DefaultEditorKit.selectLineAction); newmap.addActionForKeyStroke(L, actionL); KeyStroke W = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK); Action actionW = (Action) lookup.get(DefaultEditorKit.selectWordAction); newmap.addActionForKeyStroke(W, actionW); area.setKeymap(newmap);// w w w. j a v a2s . c o m JFrame f = new JFrame("KeymapExample"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); area.setText("www.\n java2s \n .com."); f.pack(); f.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { JFrame frame = new JFrame("Editable Color Table"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); TableModel model = new ColorTableModel(); JTable table = new JTable(model); TableColumn column = table.getColumnModel().getColumn(2); ComboTableCellRenderer renderer = new ComboTableCellRenderer(); column.setCellRenderer(renderer);/*from w w w . j av a 2 s . c om*/ TableCellEditor editor = new ColorChooserEditor(); column.setCellEditor(editor); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(400, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane pane = new JTextPane(); pane.setEditorKit(new CustomEditorKit()); pane.setText("Underline With Different Color"); StyledDocument doc = (StyledDocument) pane.getDocument(); MutableAttributeSet attrs = new SimpleAttributeSet(); attrs.addAttribute("Underline-Color", Color.red); doc.setCharacterAttributes(0, doc.getLength() - 1, attrs, true); JScrollPane sp = new JScrollPane(pane); frame.setContentPane(sp);/*w w w .j a v a2s. com*/ frame.setPreferredSize(new Dimension(400, 300)); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { JTextComponent textcomp = new JTextArea(); final UndoManager undo = new UndoManager(); Document doc = textcomp.getDocument(); doc.addUndoableEditListener(new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent evt) { undo.addEdit(evt.getEdit()); }/*from w w w .jav a 2 s .c om*/ }); textcomp.getActionMap().put("Undo", new AbstractAction("Undo") { public void actionPerformed(ActionEvent evt) { try { if (undo.canUndo()) { undo.undo(); } } catch (CannotUndoException e) { } } }); textcomp.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo"); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(textcomp)); frame.setSize(380, 320); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:MultiHighlight.java
public static void main(String args[]) { JFrame frame = new JFrame("MultiHighlight"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea area = new JTextArea(5, 20); area.setText("ww\nw.java2s.c\nom"); frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); JButton b = new JButton("Highlight All Vowels"); b.addActionListener(new MultiHighlight(area, "aeiouAEIOU")); frame.getContentPane().add(b, BorderLayout.SOUTH); frame.pack();// ww w.j a v a 2 s.c o m frame.setVisible(true); }