private JPanel createPanel2() { JPanel panel = new JPanel(); panel.setLayout(new JideBoxLayout(panel, JideBoxLayout.Y_AXIS)); panel.setBorder( BorderFactory.createCompoundBorder( new JideTitledBorder( new PartialEtchedBorder(PartialEtchedBorder.LOWERED, PartialSide.NORTH), "AutoCompletion with list and tree", JideTitledBorder.LEADING, JideTitledBorder.ABOVE_TOP), BorderFactory.createEmptyBorder(0, 0, 0, 0))); // create tree combobox final JTextField treeTextField = new JTextField(); treeTextField.setName("AutoCompletion JTextField with JTree"); SelectAllUtils.install(treeTextField); final JTree tree = new JTree(); tree.setVisibleRowCount(10); final TreeSearchable searchable = new TreeSearchable(tree); searchable.setRecursive(true); new AutoCompletion(treeTextField, searchable); panel.add(new JLabel("AutoCompletion JTextField with JTree")); panel.add(Box.createVerticalStrut(3), JideBoxLayout.FIX); panel.add(treeTextField); panel.add(Box.createVerticalStrut(2), JideBoxLayout.FIX); panel.add(new JScrollPane(tree)); panel.add(Box.createVerticalStrut(12), JideBoxLayout.FIX); // create font name combobox final JTextField fontNameTextField = new JTextField(); fontNameTextField.setName("AutoCompletion JTextField with JList"); SelectAllUtils.install(fontNameTextField); final JList fontNameList = new JList(_fontNames); fontNameList.setVisibleRowCount(10); new AutoCompletion(fontNameTextField, new ListSearchable(fontNameList)); panel.add(new JLabel("AutoCompletion JTextField with JList")); panel.add(Box.createVerticalStrut(3), JideBoxLayout.FIX); panel.add(fontNameTextField); panel.add(Box.createVerticalStrut(2), JideBoxLayout.FIX); panel.add(new JScrollPane(fontNameList)); panel.add(Box.createVerticalStrut(12), JideBoxLayout.FIX); return panel; }
public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } Action action = new GloballyContextSensitiveAction("selectAll", "selectAll", "selectAll"); JMenuBar menubar = new JMenuBar(); JMenu menu = new JMenu("Actions"); menu.add(action); menubar.add(menu); JToolBar toolbar = new JToolBar(); toolbar.setRollover(true); toolbar.setFloatable(true); toolbar.add(action); JPanel contents = new JPanel(); String[] listData = new String[] {"item1", "item2", "item3", "item4", "item5 "}; JList list = new JList(listData); contents.add(new JScrollPane(list)); JTree tree = new JTree(); tree.setVisibleRowCount(10); contents.add(new JScrollPane(tree)); JTable table = new JTable(new DefaultTableModel(new String[] {"Name", "Type", "Modified"}, 10)); table.setPreferredScrollableViewportSize(new Dimension(100, 5 * table.getRowHeight())); contents.add(new JScrollPane(table)); contents.add(new JPanel()); JFrame frame = new JFrame("Globally Context Sensitive Actions - [email protected]"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(menubar); frame.getContentPane().add(contents); frame.getContentPane().add(toolbar, BorderLayout.NORTH); frame.pack(); frame.show(); }