Bonjour,
Alors j'ai un JTextField dans lequel je rentre un chiffre ou du texte n'importe. Ensuite je clique sur un bouton. La valeur du JTextField devrait s'envoyé dans un JTextArea situé en dessous. Je voudrais que ce JTextArea ne soit pas éditable et de couleur gris.
Dans un premier temps j'ai mis mon JTextArea dans un JPanel tout simple, le textArea ne s'affiche pas. Du coup je l'ai mis dans un JScrollPane mais j'ai l'impression que chaque action (couleur ou setter du texte) ne fonctionne pas.
Voici mon code :
Merci d'avance ! En espérant avoir été clair !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85 public class DialogCommands extends JFrame { private static final long serialVersionUID = 1688086938712980285L; private JPanel mainPanel = null; private JPanel northPanel = null; private JScrollPane centerPanel = null; private JPanel southPanel = null; private JLabel inputLabel = null; private JTextArea textArea = null; private JButton buttonExecute = null; private JTextField textField = null; private JButton buttonApply = null; private JButton buttonCancel = null; private JButton buttonClose = null; public DialogCommands() { // CommandsName in parameter ? initComponent(); } private void initComponent() { mainPanel = new JPanel(); northPanel = new JPanel(); centerPanel = new JScrollPane(); southPanel = new JPanel(); inputLabel = new JLabel("Input : "); textField = new JTextField(20); buttonExecute = new JButton("Execute"); textArea = new JTextArea(); // textArea.setBackground(Color.BLUE); textArea.setEditable(true); buttonApply = new JButton("Apply"); buttonCancel = new JButton("Cancel"); buttonClose = new JButton("Close"); mainPanel.setLayout(new BorderLayout()); northPanel.add(inputLabel); northPanel.add(textField); northPanel.add(buttonExecute); centerPanel.add(textArea); southPanel.add(buttonApply); southPanel.add(buttonCancel); southPanel.add(buttonClose); mainPanel.add(northPanel, BorderLayout.NORTH); mainPanel.add(centerPanel, BorderLayout.CENTER); mainPanel.add(southPanel, BorderLayout.SOUTH); add(mainPanel); buttonExecute.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String text = textField.getText(); System.out.println("text = " + text); textArea.setText(text); } }); } public static void main(String[] args) { DialogCommands dialogCommands = new DialogCommands(); dialogCommands.setTitle("CommandsFrame"); dialogCommands.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); dialogCommands.setVisible(true); dialogCommands.toFront(); dialogCommands.setLocationRelativeTo(null); dialogCommands.setSize(450, 350); } }
Partager