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
| import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class SectionPanel extends JPanel {
private int n;
private JCheckBoxMap checkboxmap;
private String titre;
public SectionPanel(int n, String titre, String...questions) {
super(new BorderLayout());
this.n=n;
this.titre=titre;
this.checkboxmap = new JCheckBoxMap(questions);
JTextArea titrearea = new JTextArea(n+". "+titre);
titrearea.setForeground(Color.WHITE);
titrearea.setBackground(Color.decode("#0596de"));
titrearea.setEditable(false);
titrearea.setLineWrap(true);
titrearea.setWrapStyleWord(true);
titrearea.setBorder(BorderFactory.createEmptyBorder(3,3,3,3));
add(titrearea,BorderLayout.NORTH);
//Box box = Box.createVerticalBox();
JPanel box = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.weightx=1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.WEST;
box.setBackground(Color.decode("#e9f8fe"));
for(JCheckBox jcheckbox : checkboxmap) {
jcheckbox.setOpaque(false);
box.add(jcheckbox,gbc);
}
add(box); // au centre
}
public int getNumero() {
return n;
}
public String getTitre() {
return titre;
}
public int[] getSelected() {
return checkboxmap.asSet().stream()
.filter(e-> e.getValue().isSelected())
.mapToInt(e->e.getKey())
.toArray();
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridBagLayout());
frame.getContentPane().add(new JScrollPane(panel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER));
List<SectionPanel> sectionPanels = new ArrayList<>();
sectionPanels.add(new SectionPanel(1, " Vous souffrez ou avez souffert de dépression pendant au moins deux semaines.", "Une tristesse presque quotidienne, souvent toute la journée","Pas ou peu d'interêt pour quasiment toutes les activités et cela quotidiénement","Variation de l'appétit, de moins important à plus important"));
sectionPanels.add(new SectionPanel(2, "Vous vivez ou avez vécu un épisode dexcitation pendant au moins 15 jours :hyperactivité et euphorie,multiples projets,discours volubiles,comportement à risque,exaltation etc.", "q1","q2"));
sectionPanels.add(new SectionPanel(3, "titre3", "q1","q2","q3","q4"));
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.weightx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
for(SectionPanel sectionPanel : sectionPanels) {
panel.add(sectionPanel,gbc);
}
frame.pack();;
frame.setSize(800,frame.getHeight()+22);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
} |
Partager