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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
|
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Point;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.event.ListSelectionListener;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
public class FrmPrincipale extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
JList jList = null;
private DetailsMaj liste_maj[] = {
new DetailsMaj("Name1","Category1","Description1","fichier1"),
new DetailsMaj("Name2","Category2","Description2","fichier2"),
new DetailsMaj("Name3","Category3","Description3","fichier3"),}; // @jve:decl-index=0:
private JPanel jPanel = null;
private JButton jButton = null;
/**
* This method initializes jList
*
* @return javax.swing.JList
*/
private JList getJList() {
if (jList == null) {
jList = new JList(liste_maj);
jList.setCellRenderer(new MyCellRenderer());
jList.setBounds(new Rectangle(19, 20, 442, 244));
jList.setVisible(true);
}
return jList;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
FrmPrincipale thisClass = new FrmPrincipale();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}catch(Exception e){
e.printStackTrace();
}
}
});
}
/**
* This is the default constructor
*/
public FrmPrincipale() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(566, 553);
this.setContentPane(getJContentPane());
this.setTitle("JFrame");
this.setVisible(true);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJList(), null);
}
return jContentPane;
}
class MyCellRenderer extends JPanel implements ListCellRenderer{
private static final long serialVersionUID = -3215690257749168708L;
public JLabel name ;
public JLabel category;
public JTextArea description;
public JButton boutonExecuter;
public JPanel container;
public JScrollPane scrollPane ;
public MyCellRenderer() {
super( new BorderLayout() );
setBorder( BorderFactory.createCompoundBorder(
BorderFactory.createMatteBorder( 0, 0, 1, 0, Color.lightGray ),
BorderFactory.createEmptyBorder( 3, 3, 3, 3 ) ) );
setOpaque( false );
Font styleSimple = (new JLabel( "font" )).getFont();
Font styleGras = new Font( styleSimple.getName(),
Font.BOLD, styleSimple.getSize() );
name = new JLabel();
name.setFont( styleGras );
name.setOpaque( false );
category = new JLabel();
category.setFont( styleSimple );
category.setOpaque( false );
description = new JTextArea();
description.setBorder( BorderFactory.createEmptyBorder( 5, 0, 0, 0 ) );
description.setEditable( false );
description.setFont( (new JLabel()).getFont() );
description.setOpaque( false );
description.setLineWrap( true );
description.setWrapStyleWord( true );
boutonExecuter = new JButton( "Executer" );
JPanel boutonPanel = new JPanel( new FlowLayout( FlowLayout.RIGHT ) );
boutonPanel.add( boutonExecuter );
boutonPanel.setOpaque( false );
JPanel p1 = new JPanel( new BorderLayout() );
p1.add( name, BorderLayout.NORTH );
p1.add( category, BorderLayout.CENTER );
p1.setOpaque( false );
JPanel p2 = new JPanel( new BorderLayout() );
p2.add( p1, BorderLayout.WEST );
p2.add( boutonPanel, BorderLayout.EAST );
p2.setOpaque( false );
container = new JPanel( new BorderLayout() );
container.add( p2, BorderLayout.NORTH );
container.add( description, BorderLayout.SOUTH );
container.setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) );
Dimension d = description.getPreferredSize();
d.setSize( 635, d.getHeight() );
description.setPreferredSize( d );
add( container, BorderLayout.CENTER );
}
public Component getListCellRendererComponent(JList list, Object value,int index, boolean isSelected, boolean cellHasFocus)
{
DetailsMaj s = (DetailsMaj) value;
name.setText(s.getName());
category.setText(s.getCategory());
description.setText(s.getDescription());
if( isSelected || list.getSelectedIndex()==index ) {
name.setForeground( list.getSelectionForeground() );
category.setForeground( list.getSelectionForeground() );
description.setForeground( list.getSelectionForeground() );
container.setBackground( list.getSelectionBackground() );
boutonExecuter.setEnabled(true);
boutonExecuter.setUI( (new JButton()).getUI() );
} else {
name.setForeground( (new JLabel()).getForeground() );
category.setForeground( (new JLabel()).getForeground() );
description.setForeground( (new JLabel()).getForeground() );
container.setBackground( list.getBackground() );
boutonExecuter.setEnabled( false );
boutonExecuter.setUI( null );
}
return this;
}
}
class ExecListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
System.out.print("OUI");
}
}
class DetailsMaj {
private String prmName;
private String prmCategory;
private String prmDescription;
private String prmFichier;
public DetailsMaj(String prmName, String prmCategory, String prmDescription, String prmFichier) {
this.prmName = prmName;
this.prmCategory=prmCategory;
this.prmDescription=prmDescription;
this.prmFichier=prmFichier;
}
public String getName() {
return prmName;
}
public String getCategory() {
return prmCategory;
}
public String getDescription() {
return prmDescription;
}
public String getFicheir() {
return prmFichier;
}
}
} |
Partager