Example usage for javax.swing JTextArea setPreferredSize

List of usage examples for javax.swing JTextArea setPreferredSize

Introduction

In this page you can find the example usage for javax.swing JTextArea 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:FlowLayoutExample.java

public static void main(String[] args) {
    JPanel panel = new JPanel();
    JTextArea area = new JTextArea("text area");
    area.setPreferredSize(new Dimension(100, 100));

    JButton button = new JButton("button");
    panel.add(button);/*from  ww  w .j a v a2  s  . c  o m*/

    panel.add(new JScrollPane(area));

    JFrame f = new JFrame();
    f.add(panel);
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:FlowLayoutTest.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("FlowLayout Test");
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String text = "A JTextArea object represents" + "a multiline area for displaying text."
            + "You can change the number of lines" + "that can be displayed at a time.";
    JTextArea textArea1 = new JTextArea(text, 5, 10);
    textArea1.setPreferredSize(new Dimension(100, 100));
    JTextArea textArea2 = new JTextArea(text, 5, 10);
    textArea2.setPreferredSize(new Dimension(100, 100));
    JScrollPane scrollPane = new JScrollPane(textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    textArea1.setLineWrap(true);/*from ww  w.java2  s .c o m*/
    textArea2.setLineWrap(true);
    frame.add(textArea1);
    frame.add(scrollPane);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    JTextArea b = new JTextArea();
    b.setPreferredSize(new Dimension(600, 600));
    JScrollPane pane = new JScrollPane(b);
    AdjustmentListener hListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("Horizontal: ");
            dumpInfo(e);/*from   w w  w .j  a  v  a2  s .  c  o m*/
        }
    };
    JScrollBar hBar = pane.getHorizontalScrollBar();
    hBar.addAdjustmentListener(hListener);
    AdjustmentListener vListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("Vertical: ");
            dumpInfo(e);
        }
    };
    JScrollBar vBar = pane.getVerticalScrollBar();
    vBar.addAdjustmentListener(vListener);
    contentPane.add(pane, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    String text = "A JTextArea object represents a multiline area for displaying text. "
            + "You can change the number of lines that can be displayed at a time, "
            + "as well as the number of columns. You can wrap lines and words too. "
            + "You can also put your JTextArea in a JScrollPane to make it scrollable.";

    JTextArea textAreal = new JTextArea(text, 5, 10);
    textAreal.setPreferredSize(new Dimension(100, 100));
    JTextArea textArea2 = new JTextArea(text, 5, 10);
    textArea2.setPreferredSize(new Dimension(100, 100));
    JScrollPane scrollPane = new JScrollPane(textArea2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    textAreal.setLineWrap(true);/*from w  w w .  j  a  v a 2s .  com*/
    textArea2.setLineWrap(true);
    frame.add(textAreal);
    frame.add(scrollPane);
    frame.pack();
    frame.setVisible(true);
}

From source file:au.org.ala.delta.ui.MessageDialogHelper.java

/**
 * Creates a text area that looks like a JLabel that has a preferredSize calculated to fit
 * all of the supplied text wrapped at the supplied column. 
 * @param text the text to display in the JTextArea.
 * @param numColumns the column number to wrap text at.
 * @return a new JTextArea configured for the supplied text.
 *//*from www.  j av  a2 s .  c  o m*/
private static JTextArea createMessageDisplay(String text, int numColumns) {
    JTextArea textArea = new JTextArea();
    textArea.setEditable(false);

    textArea.setBackground(UIManager.getColor("Label.background"));
    textArea.setFont(UIManager.getFont("Label.font"));

    textArea.setWrapStyleWord(true);
    textArea.setLineWrap(true);
    textArea.setColumns(numColumns);

    String wrapped = WordUtils.wrap(text, numColumns);
    textArea.setRows(wrapped.split("\n").length - 1);

    textArea.setText(text);

    // Need to set a preferred size so that under OpenJDK-6 on Linux the JOptionPanes get reasonable bounds 
    textArea.setPreferredSize(new Dimension(0, 0));

    return textArea;

}

From source file:MainClass.java

public MainClass() {
    super("Simple SplitPane Frame");
    setSize(450, 200);//  ww  w .  jav a2s .c om
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JTextArea jt1 = new JTextArea(sometext);
    JTextArea jt2 = new JTextArea(sometext);

    jt1.setLineWrap(true);
    jt2.setLineWrap(true);
    jt1.setMinimumSize(new Dimension(150, 150));
    jt2.setMinimumSize(new Dimension(150, 150));
    jt1.setPreferredSize(new Dimension(250, 200));
    JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jt1, jt2);
    getContentPane().add(sp, BorderLayout.CENTER);
}

From source file:SimpleSplitPane.java

public SimpleSplitPane() {
    super("Simple SplitPane Frame");
    setSize(450, 200);//w  w w  . j a va2s.c  o m
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JTextArea jt1 = new JTextArea(sometext);
    JTextArea jt2 = new JTextArea(sometext);

    // Make sure our text boxes do line wrapping and have reasonable
    // minimum sizes.
    jt1.setLineWrap(true);
    jt2.setLineWrap(true);
    jt1.setMinimumSize(new Dimension(150, 150));
    jt2.setMinimumSize(new Dimension(150, 150));
    jt1.setPreferredSize(new Dimension(250, 200));
    JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jt1, jt2);
    getContentPane().add(sp, BorderLayout.CENTER);
}

From source file:CubaHSQLDBServer.java

private void setTextPreserveSize(JTextArea target, String text) {
    Dimension size = target.getPreferredSize();
    target.setText(text);//  w w  w . j a  v  a 2  s. c  om
    target.setPreferredSize(size);
}

From source file:medsavant.uhn.cancer.UserCommentApp.java

private JPanel getCommentPanel(UserComment lc) {
    JTextArea commentText = new JTextArea();
    commentText.setText(lc.getCommentText());
    commentText.setEditable(false);/*from  w w w.  ja  va  2s.  co m*/
    commentText.setLineWrap(true);
    commentText.setPreferredSize(new Dimension(COMMENTTEXT_PREFERRED_WIDTH, COMMENTTEXT_PREFERRED_HEIGHT));
    JScrollPane jsp = new JScrollPane(commentText);

    JPanel outerCommentPanel = new JPanel();
    outerCommentPanel.setLayout(new BoxLayout(outerCommentPanel, BoxLayout.X_AXIS));
    outerCommentPanel.add(jsp);
    outerCommentPanel.add(Box.createHorizontalGlue());
    return outerCommentPanel;
}

From source file:ConfigFiles.java

public JPanel addPanel(String title, String description, final JTextField textfield, String fieldtext, int Y,
        boolean withbutton, ActionListener actionlistener) {
    JPanel p1 = new JPanel();
    p1.setBackground(Color.WHITE);
    TitledBorder border = BorderFactory.createTitledBorder(title);
    border.setTitleFont(new Font("Arial", Font.PLAIN, 14));
    border.setBorder(BorderFactory.createLineBorder(new Color(150, 150, 150), 1));
    p1.setBorder(border);//w w  w.j  a va2s.  com
    p1.setLayout(new BoxLayout(p1, BoxLayout.Y_AXIS));
    p1.setBounds(80, Y, 800, 75);
    paths.add(p1);
    JTextArea tcpath = new JTextArea(description);
    tcpath.setWrapStyleWord(true);
    tcpath.setLineWrap(true);
    tcpath.setEditable(false);
    tcpath.setCursor(null);
    tcpath.setOpaque(false);
    tcpath.setFocusable(false);
    tcpath.setFont(new Font("Arial", Font.PLAIN, 12));
    tcpath.setBackground(getBackground());
    tcpath.setMaximumSize(new Dimension(170, 22));
    tcpath.setPreferredSize(new Dimension(170, 22));
    tcpath.setBorder(null);
    JPanel p11 = new JPanel();
    p11.setBackground(Color.WHITE);
    p11.setLayout(new GridLayout());
    p11.add(tcpath);
    p11.setMaximumSize(new Dimension(700, 18));
    p11.setPreferredSize(new Dimension(700, 18));
    textfield.setMaximumSize(new Dimension(340, 27));
    textfield.setPreferredSize(new Dimension(340, 27));
    textfield.setText(fieldtext);
    JButton b = null;
    if (withbutton) {
        b = new JButton("...");
        if (!PermissionValidator.canChangeFWM()) {
            b.setEnabled(false);
        }
        b.setMaximumSize(new Dimension(50, 20));
        b.setPreferredSize(new Dimension(50, 20));
        if (actionlistener == null) {
            b.addActionListener(new AbstractAction() {
                public void actionPerformed(ActionEvent ev) {
                    Container c;

                    if (RunnerRepository.container != null)
                        c = RunnerRepository.container.getParent();
                    else
                        c = RunnerRepository.window;
                    try {
                        new MySftpBrowser(RunnerRepository.host, RunnerRepository.user,
                                RunnerRepository.password, textfield, c, false);
                    } catch (Exception e) {
                        System.out.println("There was a problem in opening sftp browser!");
                        e.printStackTrace();
                    }
                }
            });
        } else {
            b.addActionListener(actionlistener);
            b.setText("Save");
            b.setMaximumSize(new Dimension(70, 20));
            b.setPreferredSize(new Dimension(70, 20));
        }
    }
    JPanel p12 = new JPanel();
    p12.setBackground(Color.WHITE);
    p12.add(textfield);
    if (withbutton)
        p12.add(b);
    p12.setMaximumSize(new Dimension(700, 32));
    p12.setPreferredSize(new Dimension(700, 32));
    p1.add(p11);
    p1.add(p12);
    return p12;
}