import javax.swing.*; import javax.swing.tree.*; import javax.swing.event.*; import java.awt.*; import java.util.*; import java.io.*; public class UserGroup extends JFrame implements TreeSelectionListener { private Container mPane; private JPanel mMain = new JPanel(true); private JScrollPane mScrollPanel; private JPanel mTreePanel = new JPanel(true); private JTree mTree; private ButtonGroup allowDeny = new ButtonGroup(); public UserGroup() { super("User Groups"); GridBagConstraints cons = new GridBagConstraints(); buildTree(); mPane = this.getContentPane(); mMain.setLayout(new GridBagLayout()); cons.gridy = 0; cons.gridx = 0; cons.anchor = GridBagConstraints.WEST; JLabel txt0 = new JLabel("Click the squares to select groups to add to"); txt0.setHorizontalAlignment(SwingConstants.LEFT); mMain.add(txt0, cons); cons.gridy++; JLabel txt1 = new JLabel("this unit's permissoin group."); txt1.setHorizontalAlignment(SwingConstants.LEFT); mMain.add(txt1, cons); cons.anchor = GridBagConstraints.CENTER; mScrollPanel = new JScrollPane(mTree, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); mScrollPanel.setPreferredSize(new Dimension(250, 200)); mTreePanel.add(mScrollPanel); cons.gridy++; mMain.add(mScrollPanel, cons); cons.gridy++; cons.anchor = GridBagConstraints.WEST; Box row0 = Box.createHorizontalBox(); row0.add(new JLabel("Add Login")); cons.weightx = 1.0; row0.add(new JTextField(15)); JRadioButton allow = new JRadioButton("Allow"); allowDeny.add(allow); row0.add(allow); mMain.add(row0, cons); cons.gridx = 0; cons.gridy++; Box row1 = Box.createHorizontalBox(); row1.add(new JLabel("to permissoin group, then")); row1.add(Box.createRigidArea(new Dimension(70, 0))); JRadioButton deny = new JRadioButton("Block"); allowDeny.add(deny); row1.add(deny); mMain.add(row1, cons); cons.gridx = 0; cons.gridy++; cons.anchor = GridBagConstraints.CENTER; cons.fill = GridBagConstraints.HORIZONTAL; mMain.add(new JButton("Submit login"), cons); cons.insets = new Insets(20, 50, 0, 50); cons.gridy++; mMain.add(new JButton("Click here to view txt permissoins"), cons); cons.gridy++; cons.fill = GridBagConstraints.NONE; Box buttons = Box.createHorizontalBox(); buttons.add(new JButton("Reset")); buttons.add(new JButton("Cancel")); buttons.add(new JButton("Ok")); mMain.add(buttons, cons); mPane.add(mMain); pack(); } public void buildTree() { DefaultMutableTreeNode top = new DefaultMutableTreeNode("Anybody"); DefaultMutableTreeNode cpDept = new DefaultMutableTreeNode("Computer Science Department"); top.add(cpDept); DefaultMutableTreeNode cpe101 = new DefaultMutableTreeNode("CPE 101"); cpDept.add(cpe101); DefaultMutableTreeNode kmammen = new DefaultMutableTreeNode("kmammen"); cpe101.add(kmammen); DefaultMutableTreeNode gfisher = new DefaultMutableTreeNode("gfisher"); cpe101.add(gfisher); DefaultMutableTreeNode cpe102 = new DefaultMutableTreeNode("CPE 102"); cpDept.add(cpe102); DefaultMutableTreeNode cpe103 = new DefaultMutableTreeNode("CPE 103"); cpDept.add(cpe103); mTree = new JTree(top); mTree.setVisibleRowCount(7); TreeSelectionModel model = mTree.getSelectionModel(); model.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); mTree.setSelectionModel(model); mTree.addTreeSelectionListener(this); } public void valueChanged(TreeSelectionEvent e) { pack(); } }