Создание GUI в правильном окне

.equals() сравнивает данные в классе (при условии, что функция реализована). == сравнивает местоположения указателя (расположение объекта в памяти).

== возвращает true, если оба объекта (NOT TALKING OF PRIMITIVES) указывают на экземпляр SAME. .equals() возвращает true, если два объекта содержат одни и те же данные equals() Versus == в Java

Это может вам помочь.

0
задан Georgios 10 March 2019 в 00:25
поделиться

1 ответ

Вы можете установить высоту (количество видимых линий) JTextArea, используя setRows(). Попробуйте приведенный ниже пример. Я начал с вашего кода и сделал несколько изменений.

import javax.swing.*;
import java.awt.*;

public class ThreeLinesTextArea
{
  public static void main(String[] args)
  {
    JPanel pane = new JPanel();
    // Change to GridBagLayout
    pane.setLayout(new GridBagLayout());
    JTextField url = new JTextField("https:testin.com");
    JTextField username = new JTextField("theDude");

    JTextArea statement = new JTextArea("This statement can becomme very very very long :)");
    statement.setLineWrap(true);
    statement.setWrapStyleWord(true);
    // Use setRows() to make text area have multiple lines
    statement.setRows(3);
    JScrollPane scrollPane = new JScrollPane(statement);

    //This line is removed. scrollPane is added at the end.
    //pane.add(scrollPane);

    pane.add(new JLabel("Enter url: "),
        new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
    pane.add(url,
        new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
    pane.add(new JLabel("Enter username: "),
        new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
    pane.add(username,
        new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
    pane.add(new JLabel("Enter password: "),
        new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
    pane.add(new JPasswordField(15),
        new GridBagConstraints(1, 2, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));
    pane.add(new JLabel("Enter statement: "),
        new GridBagConstraints(0, 3, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0));
    pane.add(scrollPane,
        new GridBagConstraints(1, 3, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2, 2), 0, 0));

    int option = JOptionPane.showConfirmDialog(null, pane, "Fill all the fields",
        JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
  }
}

Вывод:

enter image description here

0
ответ дан Prasad Karunagoda 10 March 2019 в 00:25
поделиться
Другие вопросы по тегам:

Похожие вопросы: