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

public static void main(String[] args) throws Exception {
    File f = new File("index.html");
    JEditorPane jep = new JEditorPane(f.toURI().toURL());

    JScrollPane sp = new JScrollPane(jep);
    sp.setPreferredSize(new Dimension(400, 200));

    JOptionPane.showMessageDialog(null, sp);
}

From source file:Main.java

public static void main(String[] args) {
    JLabel image = new JLabel("java2s.com");
    image.setPreferredSize(new Dimension(2000, 2000));
    JScrollPane js = new JScrollPane(image);

    js.setPreferredSize(new Dimension(200, 200));

    JOptionPane.showMessageDialog(null, js);

}

From source file:Main.java

public static void main(String[] args) {
    JScrollPane sPane = new JScrollPane();
    sPane.setPreferredSize(new Dimension(200, 150));
    JButton button = new JButton(new AbstractAction("Create Table") {
        public void actionPerformed(ActionEvent arg0) {
            DefaultTableModel model = new DefaultTableModel(new Integer[][] { { 1, 2 }, { 3, 4 } },
                    new String[] { "A", "B" });
            JTable table = new JTable(model);
            sPane.getViewport().add(table);
        }//  ww  w . jav a 2s.  c o  m
    });
    JPanel panel = new JPanel();
    panel.add(sPane);
    panel.add(button);
    JOptionPane.showMessageDialog(null, panel);

}

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    Box box = Box.createVerticalBox();
    for (int i = 0; i < 100; i++) {
        box.add(new JLabel("Hello!"));
    }//from   www . j a  v a2 s .  c om
    panel.add(box);

    JTabbedPane tab = new JTabbedPane();
    JScrollPane scroll = new JScrollPane(panel);
    scroll.setPreferredSize(new Dimension(300, 300));
    tab.add(scroll, "Panel 1");

    JOptionPane.showMessageDialog(null, tab, "Test Tabbed", JOptionPane.PLAIN_MESSAGE);
}

From source file:Main.java

public static void main(String[] args) {
    JTextPane textPane = new JTextPane();
    textPane.setText("12345678\n\t1\t2\t3a");
    JScrollPane scrollPane = new JScrollPane(textPane);
    scrollPane.setPreferredSize(new Dimension(700, 100));

    setTabs(textPane, 8);/*from  w ww .  j  a va2 s  .c  o  m*/

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(scrollPane);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    int cp = 0;//  w w  w . j a  va 2s  .c  o  m
    StyledDocument doc;
    JTextPane jta = new JTextPane();
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    doc = jta.getStyledDocument();
    JScrollPane jsp = new JScrollPane(jta);
    jsp.setPreferredSize(new Dimension(400, 400));
    String[] fnt = ge.getAvailableFontFamilyNames();
    MutableAttributeSet mas = jta.getInputAttributes();
    for (int i = 0; i < fnt.length; i++) {
        StyleConstants.setBold(mas, false);
        StyleConstants.setItalic(mas, false);
        StyleConstants.setFontFamily(mas, fnt[i]);
        StyleConstants.setFontSize(mas, 16);

        doc.insertString(cp, fnt[i] + "\n", mas);

        StyleConstants.setBold(mas, true);
        doc.insertString(cp, fnt[i] + "bold \n", mas);
        StyleConstants.setItalic(mas, true);

        doc.insertString(cp, fnt[i] + "bold and italic\n", mas);
        StyleConstants.setBold(mas, false);
        doc.insertString(cp, fnt[i] + "italic\n", mas);
    }
    JFrame frm = new JFrame();
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm.setLayout(new BorderLayout());
    frm.add(jsp, BorderLayout.CENTER);
    frm.setLocation(100, 100);
    frm.pack();
    frm.setVisible(true);
}

From source file:WindowsLookAndFeelDemo.java

public static void main(String[] args) {
    try {//  w w w. ja  v  a2s  .  co  m
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } catch (Exception e) {
        e.printStackTrace();
    }
    JLabel label = new JLabel("Label");
    JTextField field = new JTextField("www.java2s.com!");
    JList list = new JList(new String[] { "A", "B", "C" });
    JScrollPane listPane = new JScrollPane(list);
    listPane.setPreferredSize(new Dimension(250, 100));

    JScrollPane treePane = new JScrollPane(new JTree());
    treePane.setPreferredSize(new Dimension(250, 100));
    JButton button = new JButton("Click me");

    JPanel cp = new JPanel();
    cp.add(label);
    cp.add(field);
    cp.add(listPane);
    cp.add(treePane);
    cp.add(button);

    JFrame frame = new JFrame();
    frame.setTitle("Windows Look and Feel Demo");
    frame.setPreferredSize(new Dimension(280, 300));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(cp);
    frame.pack();
    frame.setVisible(true);

}

From source file:GTKLookAndFeelDemo.java

public static void main(String[] args) {
    try {//from w  w w .  ja  v  a2 s.  c  o m
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
    } catch (Exception e) {
        e.printStackTrace();
    }
    JLabel label = new JLabel("Label");
    JTextField field = new JTextField("www.java2s.com!");
    JList list = new JList(new String[] { "A", "B", "C" });
    JScrollPane listPane = new JScrollPane(list);
    listPane.setPreferredSize(new Dimension(250, 100));

    JScrollPane treePane = new JScrollPane(new JTree());
    treePane.setPreferredSize(new Dimension(250, 100));
    JButton button = new JButton("Click me");

    JPanel cp = new JPanel();
    cp.add(label);
    cp.add(field);
    cp.add(listPane);
    cp.add(treePane);
    cp.add(button);

    JFrame frame = new JFrame();
    frame.setTitle("Windows Look and Feel Demo");
    frame.setPreferredSize(new Dimension(280, 300));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(cp);
    frame.pack();
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    final StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    sb.append("<body><ol>");
    Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    for (Font font : fonts) {
        String name = font.getName();
        sb.append("<li style='font-family: " + name + "; font-size: 20px;'>");
        sb.append(name);/*ww w. j a v a  2 s . co m*/
    }

    JScrollPane sp = new JScrollPane(new JLabel(sb.toString()));
    Dimension d = sp.getPreferredSize();
    sp.setPreferredSize(new Dimension(d.width, 150));
    JOptionPane.showMessageDialog(null, sp);
}

From source file:UseActions.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Use TextAction");
    Container contentPane = frame.getContentPane();
    Dimension empty = new Dimension(0, 0);

    final JTextArea leftArea = new JTextArea();
    JScrollPane leftScrollPane = new JScrollPane(leftArea);
    leftScrollPane.setPreferredSize(empty);

    final JTextArea rightArea = new JTextArea();
    JScrollPane rightScrollPane = new JScrollPane(rightArea);
    rightScrollPane.setPreferredSize(empty);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftScrollPane, rightScrollPane);

    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);/*from   ww  w.ja v  a 2  s.  c  o  m*/
    JMenu menu = new JMenu("Options");
    menuBar.add(menu);
    JMenuItem menuItem;

    Action readAction = leftArea.getActionMap().get(DefaultEditorKit.readOnlyAction);
    menuItem = menu.add(readAction);
    menuItem.setText("Make read-only");
    Action writeAction = leftArea.getActionMap().get(DefaultEditorKit.writableAction);
    menuItem = menu.add(writeAction);
    menuItem.setText("Make writable");

    menu.addSeparator();

    Action cutAction = leftArea.getActionMap().get(DefaultEditorKit.cutAction);
    menuItem = menu.add(cutAction);
    menuItem.setText("Cut");
    Action copyAction = leftArea.getActionMap().get(DefaultEditorKit.copyAction);
    menuItem = menu.add(copyAction);
    menuItem.setText("Copy");
    Action pasteAction = leftArea.getActionMap().get(DefaultEditorKit.pasteAction);
    menuItem = menu.add(pasteAction);
    menuItem.setText("Paste");

    contentPane.add(splitPane, BorderLayout.CENTER);
    frame.setSize(400, 250);
    frame.setVisible(true);
    splitPane.setDividerLocation(.5);
}