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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
/**
*
* @author thomas
*/
public class PanelMessageToSend extends JPanel {
//******************************************
//* GUI ATTRIBUTES *
//******************************************
private JButton sendButton;
private JButton newPrivateConversation;
private JScrollPane messageAreaScrollPane;
private JLabel labelVotreMessage;
private JTextArea messageArea;
//******************************************
//* CONTROLER ATTRIBUTE *
//******************************************
//private AbstractControler controler;
public PanelMessageToSend(/*AbstractControler controler*/) {
//this.controler = controler;
intcomponents();
}
private void intcomponents() {
//*************************************
//* CONSTRUCTION *
//*************************************
GridBagLayout layout = new GridBagLayout();
sendButton = new JButton("Envoyer");
newPrivateConversation = new JButton("Nouvelle Conversation");
messageArea = new JTextArea();
labelVotreMessage = new JLabel("Votre Message :");
//**************************************
//* SETTINGS *
//**************************************
messageArea.setLineWrap(true);
messageArea.setWrapStyleWord(true);
messageArea.setToolTipText("Tapez ici votre message, cliquer sur \"Envoyer\" ou faite SHIFT+ENTER pour envoyer votre message");
messageAreaScrollPane = new JScrollPane(messageArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
Dimension max = new Dimension(10, 30);
sendButton.setToolTipText("Cliquer ici pour envoyer votre message (raccourci : SHIFT+ENTER)");
newPrivateConversation.setToolTipText("Cliquer ici pour lancer une nouvelle conversation privée");
sendButton.setMaximumSize(max);
newPrivateConversation.setMaximumSize(max);
//**************************************
//* LAYOUTING *
//**************************************
this.setMinimumSize(new Dimension(600, 150));
this.setPreferredSize(new Dimension(600, 150));
this.setLayout(layout);
GridBagConstraints labelConstraint = new GridBagConstraints();
labelConstraint.gridx = labelConstraint.gridy = 0; // premier composant
labelConstraint.gridwidth = GridBagConstraints.REMAINDER; //dernier composant de la ligne (il est le seul)
labelConstraint.fill = GridBagConstraints.NONE;
labelConstraint.anchor = GridBagConstraints.LINE_START; //On le place au début de sa céllule
labelConstraint.insets = new Insets(10, 5, 0, 0);//10px en haut et à gauche, 5 en bas, 0 à droite
this.add(labelVotreMessage, labelConstraint); //ajout du composant à la fenêtre
GridBagConstraints scrollPaneConstraint = new GridBagConstraints();
scrollPaneConstraint.gridx = 0;
scrollPaneConstraint.gridy = 1;
scrollPaneConstraint.gridwidth = GridBagConstraints.RELATIVE; //avant dernier composant sur la ligne
scrollPaneConstraint.gridheight = GridBagConstraints.REMAINDER;//dernier composant sur la colonne
scrollPaneConstraint.weightx = 1;
scrollPaneConstraint.weighty = 1;
scrollPaneConstraint.anchor = GridBagConstraints.LINE_START;
scrollPaneConstraint.fill = GridBagConstraints.BOTH;
scrollPaneConstraint.insets = new Insets(10, 10, 5, 5);
this.add(messageArea, scrollPaneConstraint);
GridBagConstraints newPrivateConversationConstraints = new GridBagConstraints();
newPrivateConversationConstraints.gridx = 5;
newPrivateConversationConstraints.gridy = 10;
newPrivateConversationConstraints.gridwidth = GridBagConstraints.REMAINDER;
newPrivateConversationConstraints.gridheight = GridBagConstraints.RELATIVE;
newPrivateConversationConstraints.weighty = 1;
newPrivateConversationConstraints.weightx = 0;
newPrivateConversationConstraints.fill = GridBagConstraints.HORIZONTAL;
newPrivateConversationConstraints.anchor = GridBagConstraints.PAGE_END;
newPrivateConversationConstraints.insets = new Insets(5, 5, 5, 5);
this.add(newPrivateConversation, newPrivateConversationConstraints);
GridBagConstraints sendButtonConstraints = new GridBagConstraints();
sendButtonConstraints.gridx = 5;
sendButtonConstraints.gridy = 11;
sendButtonConstraints.gridheight = sendButtonConstraints.gridwidth = GridBagConstraints.REMAINDER;
sendButtonConstraints.weightx = sendButtonConstraints.weighty = 0;
sendButtonConstraints.fill = GridBagConstraints.HORIZONTAL;
sendButtonConstraints.anchor = GridBagConstraints.PAGE_END;
sendButtonConstraints.insets = new Insets(5, 5, 5, 5);
this.add(sendButton, sendButtonConstraints);
}
} |
Partager