Example usage for javax.swing JScrollPane setPreferredSize

List of usage examples for javax.swing JScrollPane setPreferredSize

Introduction

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

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:Main.java

private void addComponentsToPane() {

    JButton button = new JButton("Clear");
    button.addActionListener(this);

    typingArea = new JTextField(20);
    typingArea.addKeyListener(this);

    displayArea = new JTextArea();
    displayArea.setEditable(false);//from w  w w  .jav  a 2  s. c o m
    JScrollPane scrollPane = new JScrollPane(displayArea);
    scrollPane.setPreferredSize(new Dimension(375, 125));

    getContentPane().add(typingArea, BorderLayout.PAGE_START);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    getContentPane().add(button, BorderLayout.PAGE_END);
}

From source file:ListAlgorithmsBC.java

private ListAlgorithmsBC() {
    super("JCE Algorithms");
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Providers");
    DefaultTreeModel treeModel = new DefaultTreeModel(root);
    for (Provider provider : java.security.Security.getProviders()) {
        DefaultMutableTreeNode providerNode = new DefaultMutableTreeNode(provider);
        root.add(providerNode);/*w w  w . j a  va 2 s  . c om*/
        Set<Provider.Service> used = new HashSet<Provider.Service>();

        getNodes(providerNode, provider, used, "Cipher", "cipher");
        getNodes(providerNode, provider, used, "Key Agreement", "keyagreement");
        getNodes(providerNode, provider, used, "Key Generator", "keygenerator");
        getNodes(providerNode, provider, used, "Key Pair Generator", "keypairgenerator");
        getNodes(providerNode, provider, used, "Key Factory", "keyfactory");
        getNodes(providerNode, provider, used, "Secret Key Factory", "secretkeyfactory");
        getNodes(providerNode, provider, used, "Mac", "mac");
        getNodes(providerNode, provider, used, "Message Digest", "messagedigest");
        getNodes(providerNode, provider, used, "Signature", "signature");
        getNodes(providerNode, provider, used, "Algorithm Paramater", "algorithmparameters");
        getNodes(providerNode, provider, used, "Algorithm Paramater Generator", "algorithmparametergenerator");
        getNodes(providerNode, provider, used, "Key Store", "keystore");
        getNodes(providerNode, provider, used, "Secure Random", "securerandom");
        getNodes(providerNode, provider, used, "Certificate Factory", "certificatefactory");
        getNodes(providerNode, provider, used, "Certificate Store", "certstore");
        getNodes(providerNode, provider, used, "Key Manager Factory", "KeyManagerFactory");
        getNodes(providerNode, provider, used, "Trust Manager Factory", "TrustManagerFactory");
        getNodes(providerNode, provider, used, "SSL Context", "SSLContext");
        getNodes(providerNode, provider, used, "Sasl Server Factory", "SaslServerFactory");
        getNodes(providerNode, provider, used, "Sasl Client Factory", "SaslClientFactory");
        {
            DefaultMutableTreeNode node = new DefaultMutableTreeNode("Other");
            for (Provider.Service service : provider.getServices()) {
                if (!used.contains(service)) {
                    DefaultMutableTreeNode serviceNode = new DefaultMutableTreeNode(
                            service.getType() + " : " + service.getAlgorithm());
                    node.add(serviceNode);
                    serviceNode.add(new DefaultMutableTreeNode("class : " + service.getClassName()));
                }
            }
            if (node.getChildCount() != 0)
                providerNode.add(node);
        }
    }

    JTree tree = new JTree(treeModel);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setEditable(false);
    JScrollPane pane = new JScrollPane(tree);
    pane.setPreferredSize(new Dimension(200, 200));

    getContentPane().add(pane);

    pack();
}

From source file:Main.java

private void initComponents() {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JTextPane textPane = new JTextPane();
    ((AbstractDocument) textPane.getDocument()).addDocumentListener(new DocumentListener() {
        @Override/* w  ww. j  ava  2 s .com*/
        public void insertUpdate(final DocumentEvent de) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    try {
                        StyledDocument doc = (StyledDocument) de.getDocument();
                        int start = Utilities.getRowStart(textPane, Math.max(0, de.getOffset() - 1));
                        int end = Utilities.getWordStart(textPane, de.getOffset() + de.getLength());

                        String text = doc.getText(start, end - start);

                        for (String emoticon : imageTokens) {
                            int i = text.indexOf(emoticon);
                            while (i >= 0) {
                                final SimpleAttributeSet attrs = new SimpleAttributeSet(
                                        doc.getCharacterElement(start + i).getAttributes());
                                if (StyleConstants.getIcon(attrs) == null) {
                                    switch (emoticon) {
                                    case imageToken:
                                        StyleConstants.setIcon(attrs, anImage);
                                        break;
                                    }
                                    doc.remove(start + i, emoticon.length());
                                    doc.insertString(start + i, emoticon, attrs);
                                }
                                i = text.indexOf(emoticon, i + emoticon.length());
                            }
                        }
                    } catch (BadLocationException ex) {
                        ex.printStackTrace();
                    }
                }
            });
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });

    JScrollPane scrollPane = new JScrollPane(textPane);
    scrollPane.setPreferredSize(new Dimension(300, 300));
    frame.add(scrollPane);
    frame.pack();
    frame.setVisible(true);
}

From source file:TextViewer.java

/**
 * Constructor/* www .  ja v a 2  s. c  o  m*/
 */
public TextViewer() {
    super(new GridLayout(1, 1));

    // create the text area
    text_area = new JTextArea();
    text_area.setEditable(false);
    text_area.setLineWrap(true);

    // create a scroll pane for the JTextArea
    JScrollPane sp = new JScrollPane();
    sp.setPreferredSize(new Dimension(300, 300));
    sp.getViewport().add(text_area);

    add(sp);
}

From source file:Main.java

MyPanel() {
    JScrollPane scrollpane = new JScrollPane();
    scrollpane.setViewport(viewport);//from w ww  .  j a  v  a2 s.  c o  m
    viewport.add(innerPanel);
    scrollpane.setPreferredSize(SCROLLPANE_SIZE);
    viewport.addChangeListener(e -> {
        Rectangle viewRect = viewport.getViewRect();
        if (viewRect.intersects(RECT)) {
            statusLabel.setText(VISIBLE);
        } else {
            statusLabel.setText(NOT_VISIBLE);
        }
    });

    setLayout(new BorderLayout());
    add(scrollpane, BorderLayout.CENTER);
    add(statusLabel, BorderLayout.SOUTH);
}

From source file:com.googlecode.logVisualizer.chart.AreaListChartMouseEventListener.java

public void chartMouseClicked(final ChartMouseEvent e) {
    if (e.getEntity() instanceof CategoryItemEntity) {
        final CategoryItemEntity entity = (CategoryItemEntity) e.getEntity();
        final String areaName = (String) entity.getColumnKey();

        final StringBuilder str = new StringBuilder(100);
        for (final TurnInterval ti : logData.getTurnIntervalsSpent())
            if (ti.getAreaName().equals(areaName))
                str.append(ti + "\n");

        final JScrollPane text = new JScrollPane(new JTextArea(str.toString()));
        text.setPreferredSize(new Dimension(450, 200));
        JOptionPane.showMessageDialog(null, text, "Occurences of turns spent at " + areaName,
                JOptionPane.INFORMATION_MESSAGE);
    }/*  ww  w. ja va2  s.co  m*/
}

From source file:com.googlecode.logVisualizer.chart.TurnsSpentInLevelChartMouseEventListener.java

public void chartMouseClicked(final ChartMouseEvent e) {
    if (e.getEntity() instanceof CategoryItemEntity) {
        final CategoryItemEntity entity = (CategoryItemEntity) e.getEntity();
        final Matcher m = levelNumberExtractor.matcher((String) entity.getColumnKey());
        m.find();//from  w ww . java  2 s. co  m
        final int level = Integer.parseInt(m.group(1));

        final StringBuilder str = new StringBuilder(100);
        for (final TurnInterval ti : logData.getTurnIntervalsSpent()) {
            final int levelOnStart = logData.getCurrentLevel(ti.getStartTurn()).getLevelNumber();
            final int levelOnEnd = logData.getCurrentLevel(ti.getEndTurn()).getLevelNumber();

            if (levelOnStart > level)
                break;

            if (levelOnStart == level || levelOnEnd == level)
                str.append(ti + "\n");
        }

        final JScrollPane text = new JScrollPane(new JTextArea(str.toString()));
        text.setPreferredSize(new Dimension(500, 450));
        JOptionPane.showMessageDialog(null, text, "Areas visited during level " + level,
                JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:com.googlecode.logVisualizer.chart.SkillCastOnTurnsChartMouseEventListener.java

public void chartMouseClicked(final ChartMouseEvent e) {
    if (e.getEntity() instanceof CategoryItemEntity) {
        final CategoryItemEntity entity = (CategoryItemEntity) e.getEntity();
        final String skillName = (String) entity.getColumnKey();

        final StringBuilder str = new StringBuilder(250);
        if (logData.isDetailedLog())
            for (final SingleTurn st : logData.getTurnsSpent()) {
                if (st.isSkillCast(skillName))
                    str.append(st.getTurnNumber() + ": " + getCastedSkill(st, skillName).getAmount() + "\n");
            }//from   w ww. j  a  va2s  .com
        else
            for (final TurnInterval ti : logData.getTurnIntervalsSpent())
                if (ti.isSkillCast(skillName))
                    str.append(ti.getStartTurn() + "-" + ti.getEndTurn() + ": "
                            + getCastedSkill(ti, skillName).getAmount() + "\n");

        final JScrollPane text = new JScrollPane(new JTextArea(str.toString()));
        text.setPreferredSize(new Dimension(500, 450));
        JOptionPane.showMessageDialog(null, text, "Turn numbers and amount of casts of " + skillName,
                JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:ComponentEventDemo.java

public ComponentEventDemo() {
    super(new BorderLayout());

    display = new JTextArea();
    display.setEditable(false);//w w w . j  a v a 2s. co m
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(350, 200));

    JPanel panel = new JPanel(new BorderLayout());
    label = new JLabel("This is a label", JLabel.CENTER);
    label.addComponentListener(this);
    panel.add(label, BorderLayout.CENTER);

    JCheckBox checkbox = new JCheckBox("Label visible", true);
    checkbox.addItemListener(this);
    checkbox.addComponentListener(this);
    panel.add(checkbox, BorderLayout.PAGE_END);
    panel.addComponentListener(this);

    add(scrollPane, BorderLayout.CENTER);
    add(panel, BorderLayout.PAGE_END);
    frame.addComponentListener(this);
}

From source file:Main.java

private void addComponentsToPane() {

    JButton button = new JButton("Clear");
    button.addActionListener(this);

    typingArea = new JTextField(20);
    typingArea.addKeyListener(this);

    // Uncomment this if you wish to turn off focus
    // traversal. The focus subsystem consumes
    // focus traversal keys, such as Tab and Shift Tab.
    // If you uncomment the following line of code, this
    // disables focus traversal and the Tab events will
    // become available to the key event listener.
    // typingArea.setFocusTraversalKeysEnabled(false);

    displayArea = new JTextArea();
    displayArea.setEditable(false);//  w w w.j a v  a2 s .  c o m
    JScrollPane scrollPane = new JScrollPane(displayArea);
    scrollPane.setPreferredSize(new Dimension(375, 125));

    getContentPane().add(typingArea, BorderLayout.PAGE_START);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    getContentPane().add(button, BorderLayout.PAGE_END);
}