Example usage for javax.swing JScrollPane setViewportView

List of usage examples for javax.swing JScrollPane setViewportView

Introduction

In this page you can find the example usage for javax.swing JScrollPane setViewportView.

Prototype

public void setViewportView(Component view) 

Source Link

Document

Creates a viewport if necessary and then sets its view.

Usage

From source file:Main.java

public Main() {
    MyCanvas thingy = new MyCanvas();
    setLayout(new BorderLayout());
    JPanel panel = new JPanel();
    panel.add(thingy);/*from w  ww  .j av  a2s  .  co m*/
    JScrollPane scroll = new JScrollPane();
    scroll.setViewportView(panel);
    add(scroll, BorderLayout.CENTER);
    SpinnerNumberModel spmodel = new SpinnerNumberModel(thingy.getThingySize(), 10.0, 2000.0, 10.0);
    spmodel.addChangeListener(e -> thingy.setThingySize((Double) spmodel.getNumber()));
    add(new JSpinner(spmodel), BorderLayout.NORTH);
}

From source file:Main.java

public Main() {
    JScrollPane scrollPane = new JScrollPane();
    JTextPane textPane = new JTextPane();

    scrollPane.setViewportView(textPane);
    add(scrollPane);//  ww w.  ja v a 2s  . c o m

    setTitle("Main");
    setSize(300, 300);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:Main.java

private void createAndDisplayGUI() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    tPane = new JTextPane();
    JScrollPane scroller = new JScrollPane();
    scroller.setViewportView(tPane);

    tfield.addActionListener(e -> {//from  w w w .ja v a 2 s.com
        counter++;
        if (counter == 8)
            counter = 0;
        String text = tfield.getText() + "\n";
        appendToPane(tPane, text, colours[counter]);
        tfield.selectAll();
    });

    getContentPane().add(scroller, BorderLayout.CENTER);
    getContentPane().add(tfield, BorderLayout.PAGE_END);

    setSize(200, 100);
    setVisible(true);
    tfield.requestFocusInWindow();
    tfield.setText("hi enter to start");
}

From source file:Main.java

Main() {
    setSize(500, 300);// www . j a va 2 s .  co m
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new BorderLayout());
    JScrollPane pane = new JScrollPane();
    txtMain = new JTextArea();
    pane.setViewportView(txtMain);
    this.add(pane, BorderLayout.CENTER);

    JButton btnAddText = new JButton("Add Text");
    btnAddText.addActionListener(e -> {
        txtMain.setText(txtMain.getText()
                + "\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi sagittis id nibh vel rhoncus. ");
        String text = txtMain.getText();
        txtMain.setCaretPosition(text != null ? text.length() : 0);
    });
    add(btnAddText, BorderLayout.SOUTH);
    setVisible(true);
}

From source file:Main.java

public TestPane() {
    setLayout(new BorderLayout());
    JPanel top = new JPanel(new GridBagLayout());
    top.setOpaque(false);//from ww  w .j a  v a2 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:com.opendoorlogistics.components.geocode.postcodes.impl.SummaryPanel.java

public SummaryPanel() {
    setLayout(new BorderLayout());
    text.setEditable(false);/*from  w  w w  .  j  av a 2 s. c  o m*/
    JScrollPane scrollpane = new JScrollPane(text);
    scrollpane.setViewportView(text);
    add(scrollpane, BorderLayout.CENTER);
    Dimension size = new Dimension(350, 100);
    scrollpane.setMinimumSize(new Dimension(1, (int) size.getHeight()));
    scrollpane.setPreferredSize(size);
    scrollpane.setMaximumSize(new Dimension(2000, (int) size.getHeight()));
    text.setBackground(new Color(220, 220, 220));
    text.setOpaque(true);

}

From source file:Main.java

public Main() {
    setLayout(new GridLayout(1, 3));
    tree = new JTree(getTreeModel());
    tree.setDragEnabled(true);//from   w  w  w .ja  v  a2  s.com
    tree.setPreferredSize(new Dimension(200, 400));
    JScrollPane scroll = new JScrollPane();
    scroll.setViewportView(tree);

    treeModel = getTreeModel();
    JTree secondTree = new JTree(treeModel);
    secondTree.setPreferredSize(new Dimension(200, 400));
    secondTree.setTransferHandler(new TransferHandler() {
        @Override
        public boolean importData(TransferSupport support) {
            if (!canImport(support)) {
                return false;
            }
            JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
            TreePath path = dl.getPath();
            int childIndex = dl.getChildIndex();

            String data;
            try {
                data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
            } catch (Exception e) {
                return false;
            }
            if (childIndex == -1) {
                childIndex = tree.getModel().getChildCount(path.getLastPathComponent());
            }

            DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(data);
            DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) path.getLastPathComponent();
            treeModel.insertNodeInto(newNode, parentNode, childIndex);

            tree.makeVisible(path.pathByAddingChild(newNode));
            tree.scrollRectToVisible(tree.getPathBounds(path.pathByAddingChild(newNode)));
            return true;
        }

        public boolean canImport(TransferSupport support) {
            if (!support.isDrop()) {
                return false;
            }
            support.setShowDropLocation(true);
            if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                System.out.println("only string is supported");
                return false;
            }
            JTree.DropLocation dl = (JTree.DropLocation) support.getDropLocation();
            TreePath path = dl.getPath();
            if (path == null) {
                return false;
            }
            return true;
        }
    });
    JScrollPane secondScroll = new JScrollPane();
    secondScroll.setViewportView(secondTree);

    JPanel topPanel = new JPanel(new BorderLayout());
    topPanel.add(scroll, BorderLayout.CENTER);
    JPanel btmPanel = new JPanel(new BorderLayout());
    btmPanel.add(secondScroll, BorderLayout.CENTER);

    add(topPanel);
    add(btmPanel);
}

From source file:edu.harvard.mcz.imagecapture.VerbatimListDialog.java

protected void init() {
    setTitle("Verbatim Transcriptions to parse into fields");
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    setBounds(100, 100, 1000, 600);// ww  w . j a v  a  2s.  c  om
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));
    SpecimenLifeCycle sls = new SpecimenLifeCycle();
    table = new JTable(new VerbatimCountTableModel(sls.countDistinctVerbatimValues()));
    table.setDefaultRenderer(VerbatimCount.class, new ButtonRenderer("Edit"));
    table.setDefaultEditor(VerbatimCount.class, new ButtonEditor(ButtonEditor.OPEN_VERBATIM_CLASSIFY, this));
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(table);
    contentPanel.add(scrollPane, BorderLayout.CENTER);
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            JButton cancelButton = new JButton("Close");
            cancelButton.setActionCommand("Close");
            cancelButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    setVisible(false);
                }

            });
            buttonPane.add(cancelButton);
        }
    }
}

From source file:com.mirth.connect.plugins.rtfviewer.RTFViewer.java

@Override
public void viewAttachments(List<String> attachmentIds) {
    // do viewing code

    Frame frame = new Frame("RTF Viewer");

    frame.setLayout(new BorderLayout());

    try {/*from  w ww  .j a  v a 2 s .c om*/

        Attachment attachment = parent.mirthClient.getAttachment(attachmentIds.get(0));
        byte[] rawRTF = Base64.decodeBase64(attachment.getData());
        JEditorPane jEditorPane = new JEditorPane("text/rtf", new String(rawRTF));

        if (jEditorPane.getDocument().getLength() == 0) {
            // decoded when it should not have been.  i.e.) the attachment data was not encoded.
            jEditorPane.setText(new String(attachment.getData()));
        }

        jEditorPane.setEditable(false);
        JScrollPane scrollPane = new javax.swing.JScrollPane();
        scrollPane.setViewportView(jEditorPane);
        frame.add(scrollPane);
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        frame.setSize(600, 800);

        Dimension dlgSize = frame.getSize();
        Dimension frmSize = parent.getSize();
        Point loc = parent.getLocation();

        if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) {
            frame.setLocationRelativeTo(null);
        } else {
            frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                    (frmSize.height - dlgSize.height) / 2 + loc.y);
        }

        frame.setVisible(true);
    } catch (Exception e) {
        parent.alertException(parent, e.getStackTrace(), e.getMessage());
    }
}

From source file:com.mirth.connect.plugins.textviewer.TextViewer.java

@Override
public void viewAttachments(String channelId, Long messageId, String attachmentId) {
    // do viewing code
    Frame frame = new Frame("Text Viewer");
    frame.setLayout(new BorderLayout());

    try {//from  w w  w.  j  av a  2  s.  c o m
        Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId);
        byte[] content = Base64.decodeBase64(attachment.getContent());

        boolean isRTF = attachment.getType().toLowerCase().contains("rtf");
        //TODO set character encoding
        JEditorPane jEditorPane = new JEditorPane(isRTF ? "text/rtf" : "text/plain", new String(content));

        if (jEditorPane.getDocument().getLength() == 0) {
            // decoded when it should not have been.  i.e.) the attachment data was not encoded.
            jEditorPane.setText(new String(attachment.getContent()));
        }

        jEditorPane.setEditable(false);
        JScrollPane scrollPane = new javax.swing.JScrollPane();
        scrollPane.setViewportView(jEditorPane);
        frame.add(scrollPane);
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        frame.setSize(600, 800);

        Dimension dlgSize = frame.getSize();
        Dimension frmSize = parent.getSize();
        Point loc = parent.getLocation();

        if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) {
            frame.setLocationRelativeTo(null);
        } else {
            frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                    (frmSize.height - dlgSize.height) / 2 + loc.y);
        }

        frame.setVisible(true);
    } catch (Exception e) {
        parent.alertThrowable(parent, e);
    }
}