⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 choosecolumn.java

📁 这是一个在linux环境下
💻 JAVA
字号:
package fr.umlv.projet.fenetre.table;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import fr.umlv.projet.fenetre.TabbedPane;
import fr.umlv.projet.procfs.Processuses;

/**
 * The frame to choose the column of JTable which is created by
 * <@link fr.umlv.projet.fenetre.TabbedPane TabbedPane>
 * @author Owner
 *
 */
public class ChooseColumn{
	
	private List<String> list = new ArrayList<String>();
	
	JLabel label = new JLabel("<html>Selectionnez les colonnes qui apparaitront dans <br>la page Processus du Gestionnaire des taches</html>");
	JCheckBox cb11 = new JCheckBox("User Name"); 
	JCheckBox cb12 = new JCheckBox("Name");
	
	JCheckBox cb21 = new JCheckBox("SleepAVG%");
	JCheckBox cb22 = new JCheckBox("Tgid"); 
	
	JCheckBox cb31 = new JCheckBox("Pid"); 
	JCheckBox cb32 = new JCheckBox("PPid");
	
	JCheckBox cb41 = new JCheckBox("TracerPid"); 
	JCheckBox cb42 = new JCheckBox("Uid");
	
	JCheckBox cb51 = new JCheckBox("Gid"); 
	JCheckBox cb52 = new JCheckBox("FDSize");
	
	JCheckBox cb61 = new JCheckBox("VmSize(KB)"); 
	JCheckBox cb62 = new JCheckBox("VmLck(KB)");
	
	JCheckBox cb71 = new JCheckBox("VmRSS(KB)"); 
	JCheckBox cb72 = new JCheckBox("VmData(KB)");
	
	JCheckBox cb81 = new JCheckBox("VmStk(KB)"); 
	JCheckBox cb82 = new JCheckBox("VmExe(KB)");
	
	JCheckBox cb91 = new JCheckBox("VmLib(KB)"); 
	JCheckBox cb92 = new JCheckBox("VmPTE(KB)");
	
	JCheckBox cb101 = new JCheckBox("Threads"); 
	JCheckBox cb102 = new JCheckBox("State");
	
	JCheckBox cb111 = new JCheckBox("MEM%");
	JCheckBox cb112 = new JCheckBox("CPU%");
	
	JCheckBox cb121 = new JCheckBox("CMD");
	
	final JFrame frame = new JFrame("Selection Colone");
	final JCheckBox check[]={cb11,cb12,cb21,cb22,cb31,cb32,cb41,cb42,cb51,cb52,cb61,cb62,cb71,cb72,cb81,cb82,cb91,cb92,cb101,cb111,cb112,cb121};
	
	
	JPanel p = new JPanel();
	
	
	public ChooseColumn() 
	{
		this.list = TabbedPane.getProcTableModel().getColumnName();
		init();
		choisir(list);
	}
	
	/**
	 * Get the items which should be choosed from table.
	 * @param list the list of name the columns which are already choosed
	 */
	private void choisir(List<String> list){
		for(String s : list){
			for(int i=0;i<check.length;i++){
				if(check[i].getText().equals(s)){
					check[i].setSelected(true);
					continue;
				}
			}
		}
	}
	/**
	 * To creat a new frame which contains the JCheckBoxs, it is used to chose which
	 * columns display and which columns do not display 
	 */
	private void init()
	{
		JLabel l1 = new JLabel();
		l1.setText("      ");
		JLabel l2 = new JLabel();
		l2.setText("      ");
		//label.setEditable(false);
		//label.setBackground(SystemColor.controlHighlight);
		GridBagLayout gb = new GridBagLayout();
		GridBagConstraints bc = new GridBagConstraints();
		p.setLayout(gb);
		//p.add(question);
		/***********la zero ligne***************/
		bc.gridx=0;
		bc.gridy=0;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(label,bc);
		p.add(label);
		
		/***********la premiere ligne***************/
		bc.gridx=0;
		bc.gridy=1;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(check[0],bc);
		p.add(check[0]);
		
		bc.gridx=1;
		bc.gridy=1;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(check[1],bc);
		p.add(check[1]);
		
		/***********la deuxieme ligne***************/
		bc.gridx=0;
		bc.gridy=2;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(check[2],bc);
		p.add(check[2]);
		
		bc.gridx=1;
		bc.gridy=2;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb22,bc);
		p.add(cb22);
		
		/***********la troisieme ligne***************/
		bc.gridx=0;
		bc.gridy=3;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb31,bc);
		p.add(cb31);
		
		bc.gridx=1;
		bc.gridy=3;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb32,bc);
		p.add(cb32);
		
		/***********la quatrieme ligne***************/
		bc.gridx=0;
		bc.gridy=4;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb41,bc);
		p.add(cb41);
		
		bc.gridx=1;
		bc.gridy=4;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb42,bc);
		p.add(cb42);
		
		/***********la cinquieme ligne***************/
		bc.gridx=0;
		bc.gridy=5;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb51,bc);
		p.add(cb51);
		
		bc.gridx=1;
		bc.gridy=5;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb52,bc);
		p.add(cb52);
		
		/***********la sixieme ligne***************/
		bc.gridx=0;
		bc.gridy=6;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb61,bc);
		p.add(cb61);
		
		bc.gridx=1;
		bc.gridy=6;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb62,bc);
		p.add(cb62);
		
		/***********la septieme ligne***************/
		bc.gridx=0;
		bc.gridy=7;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb71,bc);
		p.add(cb71);
		
		bc.gridx=1;
		bc.gridy=7;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb72,bc);
		p.add(cb72);
		
		/***********la huitieme ligne***************/
		bc.gridx=0;
		bc.gridy=8;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb81,bc);
		p.add(cb81);
		
		bc.gridx=1;
		bc.gridy=8;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb82,bc);
		p.add(cb82);
		
		/***********la neuvieme ligne***************/
		bc.gridx=0;
		bc.gridy=9;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb91,bc);
		p.add(cb91);
		
		bc.gridx=1;
		bc.gridy=9;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb92,bc);
		p.add(cb92);
		
		/***********la dixieme ligne***************/
		bc.gridx=0;
		bc.gridy=10;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb101,bc);
		p.add(cb101);
		
		bc.gridx=1;
		bc.gridy=10;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb102,bc);
		p.add(cb102);
		
		/***********la onzieme ligne***************/
		bc.gridx=0;
		bc.gridy=11;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb111,bc);
		p.add(cb111);
		
		bc.gridx=1;
		bc.gridy=11;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb112,bc);
		p.add(cb112);
		
		/***********la douzieme ligne***************/
		bc.gridx=0;
		bc.gridy=12;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(cb121,bc);
		p.add(cb121);
		
		bc.gridx=1;
		bc.gridy=12;
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.WEST;
		gb.setConstraints(l2,bc);
		p.add(l2);
		
		/***********la toisieme ligne***************/
		bc.gridx=0;
		bc.gridy=18;
		JButton ok = new JButton("  O K  ");
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.SOUTHEAST;
		gb.setConstraints(ok,bc);
		p.add(ok);
		ok.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				List<String> tmp = new ArrayList<String>();
				for(int i=0;i<check.length;i++)
				{
					if(check[i].isSelected()==true)
					{
						tmp.add(check[i].getText());
					}
				}
				if(tmp.size()==0){
					JOptionPane.showMessageDialog(null, "Fail to choose( min 1 )", "Error!", JOptionPane.ERROR_MESSAGE);
				}
				else{
					list.clear();
					list.addAll(tmp);
					if(!list.contains(TabbedPane.getProcTableModel().getSortColumnName()))
						TabbedPane.getProcTableModel().setSortColumnName(TabbedPane.getProcTableModel().getColumnName(0));
					TabbedPane.getProcTableModel().setColumnName(list);
					TabbedPane.getProcTableModel().setData(ConverData.covert(Processuses.getProcessusList(),TabbedPane.getProcTableModel().getColumnName()));
					TabbedPane.getProcTableModel().fireTableStructureChanged();
					TabbedPane.getProcTableModel().fireTableDataChanged();
					TabbedPane.getJtp().repaint();
					frame.dispose();
				}
			}
		});
		
		bc.gridx=1;
		bc.gridy=18;
		JButton annuler = new JButton("Cancel");
		bc.fill= GridBagConstraints.NONE;
		bc.anchor = GridBagConstraints.SOUTHWEST;
		gb.setConstraints(annuler,bc);
		p.add(annuler);
		annuler.addActionListener(new java.awt.event.ActionListener(){
			public void actionPerformed(ActionEvent e) {
				frame.dispose();
			}
		});
		
		frame.setContentPane(p);
		frame.setSize(450,500);
		frame.setResizable(false);
		frame.setLocation(300,200);
		frame.setTitle("Selection de colonne");
		frame.setVisible(true);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -