List of usage examples for javax.swing JSplitPane setOneTouchExpandable
@BeanProperty(description = "UI widget on the divider to quickly expand/collapse the divider.") public void setOneTouchExpandable(boolean newValue)
oneTouchExpandable
property, which must be true
for the JSplitPane
to provide a UI widget on the divider to quickly expand/collapse the divider. From source file:com.choicemaker.cm.modelmaker.gui.panels.HoldVsAccuracyPlotPanel.java
private void layoutPanel() { GridBagLayout layout = new GridBagLayout(); setLayout(layout);/*from w ww .j a v a 2 s. c om*/ layout.columnWeights = new double[] { 1f, 0f }; layout.columnWidths = new int[] { 200, 300 }; GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 5, 10); //Row 0.......................................................... //histo c.gridy = 0; c.gridx = 0; c.gridwidth = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; ChartPanel p = new ChartPanel(chart, false, false, false, true, true); // p.setHorizontalZoom(true); // p.setVerticalZoom(true); add(p, c); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setDividerSize(2); splitPane.setContinuousLayout(true); splitPane.setDividerLocation(0.5d); splitPane.setResizeWeight(0.5f); splitPane.setOneTouchExpandable(true); splitPane.setTopComponent(accuracyPanel); splitPane.setBottomComponent(hrPanel); c.gridx = 1; c.gridheight = 1; add(splitPane, c); }
From source file:com.joey.software.Tools.AScanViewerTool.java
public void createJPanel() { JSplitPane graphSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT); graphSplit.setLeftComponent(previewPanel); graphSplit.setRightComponent(dataPanel); graphSplit.setOneTouchExpandable(true); graphSplit.setDividerLocation(400);/*from www.j a v a 2 s . c om*/ JPanel graphHolder = new JPanel(new BorderLayout()); graphHolder.add(graphSplit, BorderLayout.CENTER); graphHolder.setBorder(BorderFactory.createTitledBorder("")); JPanel tool = new JPanel(new BorderLayout()); tool.add(saveCSVData, BorderLayout.SOUTH); tool.add(aScanType, BorderLayout.CENTER); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.add(graphHolder, BorderLayout.CENTER); leftPanel.add(tool, BorderLayout.SOUTH); JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); split.setOneTouchExpandable(true); split.setRightComponent(imageViewPanel); split.setLeftComponent(leftPanel); split.setDividerLocation(600); JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(split, BorderLayout.CENTER); getContentPane().setLayout(new BorderLayout()); getContentPane().add(mainPanel); aScanType.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { imageViewPanel.setViewType(aScanType.getSelectedIndex()); } }); saveCSVData.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { File f = FileSelectionField.getUserFile(); f = FileOperations.renameFileType(f, "csv"); saveAScanData(f); } catch (Exception e1) { JOptionPane.showMessageDialog(null, "Error : " + e1.getLocalizedMessage(), "Error Saving Data", JOptionPane.ERROR_MESSAGE); e1.printStackTrace(); } } }); }
From source file:BasicDnD.java
public BasicDnD() { super(new BorderLayout()); JPanel leftPanel = createVerticalBoxPanel(); JPanel rightPanel = createVerticalBoxPanel(); // Create a table model. DefaultTableModel tm = new DefaultTableModel(); tm.addColumn("Column 0"); tm.addColumn("Column 1"); tm.addColumn("Column 2"); tm.addColumn("Column 3"); tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" }); tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" }); tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" }); tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" }); // LEFT COLUMN // Use the table model to create a table. table = new JTable(tm); leftPanel.add(createPanelForComponent(table, "JTable")); // Create a color chooser. colorChooser = new JColorChooser(); leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser")); // RIGHT COLUMN // Create a textfield. textField = new JTextField(30); textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast"); rightPanel.add(createPanelForComponent(textField, "JTextField")); // Create a scrolled text area. textArea = new JTextArea(5, 30); textArea.setText("Favorite shows:\nBuffy, Alias, Angel"); JScrollPane scrollPane = new JScrollPane(textArea); rightPanel.add(createPanelForComponent(scrollPane, "JTextArea")); // Create a list model and a list. DefaultListModel listModel = new DefaultListModel(); listModel.addElement("Martha Washington"); listModel.addElement("Abigail Adams"); listModel.addElement("Martha Randolph"); listModel.addElement("Dolley Madison"); listModel.addElement("Elizabeth Monroe"); listModel.addElement("Louisa Adams"); listModel.addElement("Emily Donelson"); list = new JList(listModel); list.setVisibleRowCount(-1);/*from w w w .ja va 2 s . c om*/ list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport info) { // we only import Strings if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); if (dl.getIndex() == -1) { return false; } return true; } public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; } // Check for String flavor if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { displayDropLocation("List doesn't accept a drop of this type."); return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); DefaultListModel listModel = (DefaultListModel) list.getModel(); int index = dl.getIndex(); boolean insert = dl.isInsert(); // Get the current string under the drop. String value = (String) listModel.getElementAt(index); // Get the string that is being dropped. Transferable t = info.getTransferable(); String data; try { data = (String) t.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } // Display a dialog with the drop information. String dropValue = "\"" + data + "\" dropped "; if (dl.isInsert()) { if (dl.getIndex() == 0) { displayDropLocation(dropValue + "at beginning of list"); } else if (dl.getIndex() >= list.getModel().getSize()) { displayDropLocation(dropValue + "at end of list"); } else { String value1 = (String) list.getModel().getElementAt(dl.getIndex() - 1); String value2 = (String) list.getModel().getElementAt(dl.getIndex()); displayDropLocation(dropValue + "between \"" + value1 + "\" and \"" + value2 + "\""); } } else { displayDropLocation(dropValue + "on top of " + "\"" + value + "\""); } /** * This is commented out for the basicdemo.html tutorial page. * If you * add this code snippet back and delete the * "return false;" line, the * list will accept drops * of type string. // Perform the actual * import. if (insert) { listModel.add(index, data); } else { * listModel.set(index, data); } return true; */ return false; } public int getSourceActions(JComponent c) { return COPY; } protected Transferable createTransferable(JComponent c) { JList list = (JList) c; Object[] values = list.getSelectedValues(); StringBuffer buff = new StringBuffer(); for (int i = 0; i < values.length; i++) { Object val = values[i]; buff.append(val == null ? "" : val.toString()); if (i != values.length - 1) { buff.append("\n"); } } return new StringSelection(buff.toString()); } }); list.setDropMode(DropMode.ON_OR_INSERT); JScrollPane listView = new JScrollPane(list); listView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(listView, "JList")); // Create a tree. DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia"); DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon"); rootNode.add(sharon); DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya"); sharon.add(maya); DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya"); sharon.add(anya); sharon.add(new DefaultMutableTreeNode("Bongo")); maya.add(new DefaultMutableTreeNode("Muffin")); anya.add(new DefaultMutableTreeNode("Winky")); DefaultTreeModel model = new DefaultTreeModel(rootNode); tree = new JTree(model); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JScrollPane treeView = new JScrollPane(tree); treeView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(treeView, "JTree")); // Create the toggle button. toggleDnD = new JCheckBox("Turn on Drag and Drop"); toggleDnD.setActionCommand("toggleDnD"); toggleDnD.addActionListener(this); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); splitPane.setOneTouchExpandable(true); add(splitPane, BorderLayout.CENTER); add(toggleDnD, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
From source file:hermes.browser.actions.AbstractFIXBrowserDocumentComponent.java
protected void init() { headerScrollPane.setViewportView(getHeaderComponent()); bottomPanel.add(new FilterablePanel(), BorderLayout.NORTH); bottomPanel.add(getStatusPanel(), BorderLayout.SOUTH); getTopPanel().setLayout(new BorderLayout()); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setDividerLocation(200);/*from ww w. ja va 2 s . co m*/ splitPane.setOneTouchExpandable(false); splitPane.setContinuousLayout(false); splitPane.add(headerScrollPane, "top"); splitPane.add(messageTabbedPane, "bottom"); messageTabbedPane.setTabPlacement(JTabbedPane.BOTTOM); getTopPanel().add(splitPane, BorderLayout.CENTER); getTopPanel().add(getBottomComponent(), BorderLayout.SOUTH); HermesBrowser.getBrowser().addDocumentComponent(this); addDocumentComponentListener(this); updateTableRows(true); }
From source file:TextComponentDemo.java
public TextComponentDemo() { super("TextComponentDemo"); // Create the text pane and configure it. textPane = new JTextPane(); textPane.setCaretPosition(0);/* www . j a v a 2 s . c o m*/ textPane.setMargin(new Insets(5, 5, 5, 5)); StyledDocument styledDoc = textPane.getStyledDocument(); if (styledDoc instanceof AbstractDocument) { doc = (AbstractDocument) styledDoc; //doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS)); } else { System.err.println("Text pane's document isn't an AbstractDocument!"); System.exit(-1); } JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(200, 200)); // Create the text area for the status log and configure it. changeLog = new JTextArea(5, 30); changeLog.setEditable(false); JScrollPane scrollPaneForLog = new JScrollPane(changeLog); // Create a split pane for the change log and the text area. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog); splitPane.setOneTouchExpandable(true); // Create the status area. JPanel statusPane = new JPanel(new GridLayout(1, 1)); CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status"); statusPane.add(caretListenerLabel); // Add the components. getContentPane().add(splitPane, BorderLayout.CENTER); getContentPane().add(statusPane, BorderLayout.PAGE_END); // Set up the menu bar. createActionTable(textPane); JMenu editMenu = createEditMenu(); JMenu styleMenu = createStyleMenu(); JMenuBar mb = new JMenuBar(); mb.add(editMenu); mb.add(styleMenu); setJMenuBar(mb); // Add some key bindings. addBindings(); // Put the initial text into the text pane. initDocument(); // Start watching for undoable edits and caret changes. doc.addUndoableEditListener(new MyUndoableEditListener()); textPane.addCaretListener(caretListenerLabel); doc.addDocumentListener(new MyDocumentListener()); }
From source file:daylightchart.gui.DaylightChartGui.java
/** * Creates a new instance of a Daylight Chart main window. * * @param location/*ww w.j ava 2 s .c o m*/ * Location for a single chart window, or null for the full UI * @param slimUi * Whether to use a slim user interface */ public DaylightChartGui(final Location location, final boolean slimUi) { this.slimUi = slimUi; setIconImage(new ImageIcon(DaylightChartGui.class.getResource("/daylightchart.png")) //$NON-NLS-1$ .getImage()); setTitle("Daylight Chart"); //$NON-NLS-1$ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); if (location == null) { // Create basic UI locationsTabbedPane = new LocationsTabbedPane(); locationsList = new LocationsList(this); if (slimUi) { getContentPane().add(locationsList); } else { final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, locationsList, locationsTabbedPane); splitPane.setOneTouchExpandable(true); getContentPane().add(splitPane); } // Create menus and toolbars final JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); final JToolBar toolBar = new JToolBar(); toolBar.setRollover(true); add(toolBar, BorderLayout.NORTH); createFileMenu(menuBar, toolBar); createActions(menuBar, toolBar); createOptionsMenu(menuBar, toolBar); createHelpMenu(menuBar, toolBar); // Open the first location Location firstTabLocation; final Collection<Location> recentLocations = UserPreferences.recentLocationsFile().getData(); if (recentLocations.size() > 0) { firstTabLocation = recentLocations.iterator().next(); } else { firstTabLocation = locationsList.getSelectedLocation(); } addLocationTab(firstTabLocation); } else { locationsTabbedPane = null; locationsList = null; final DaylightChartReport daylightChartReport = new DaylightChartReport(location, UserPreferences.optionsFile().getData()); final ChartPanel chartPanel = new ChartPanel(daylightChartReport.getChart()); chartPanel.setPreferredSize(ChartConfiguration.chartDimension); setContentPane(chartPanel); } pack(); }
From source file:fedroot.dacs.swingdemo.DacsClientFrame.java
/** * /*from w w w . java 2 s . c o m*/ * @param dacsClientContext * @param feduri * @throws java.lang.Exception */ public DacsClientFrame(DacsClientContext dacsClientContext, Federation federation) throws Exception { logger.log(Level.INFO, "Federation {0}", federation.getFederationName()); this.federation = federation; this.dacsClientContext = dacsClientContext; // this.dacsClientContext.setDacs902EventHandler(federation, new Event902Handler(this)); // this.dacsClientContext.setDacs905EventHandler(federation, new Event905Handler(this)); JPanel mainPanel = new JPanel(new BorderLayout()); JPanel gotoUrlPanel = new JPanel(new FlowLayout()); JPanel actionPanel = new JPanel(new FlowLayout()); JPanel modifiersPanel = new JPanel(new FlowLayout()); /** Enable/Disable DACS Check_only mode */ checkOnlyCheckBox = new JCheckBox("Enable DACS Check Only", false); checkOnlyCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (checkOnlyCheckBox.isSelected()) { enableEventHandlingCheckBox.setSelected(false); enableEventHandlingCheckBox.setEnabled(false); } else { enableEventHandlingCheckBox.setEnabled(true); } } }); /** Enable/Disable Event Handling */ enableEventHandlingCheckBox = new JCheckBox("Enable Event Handling", false); final JButton btnGOTO = new JButton("Goto URL"); btnGOTO.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { followUrl(new URI(urlTextField.getText().trim())); } catch (URISyntaxException ex) { // TODO implement popup for error messages } } }); final JButton btnGO = new JButton("GO"); btnGO.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { followUrl(new URI(actionUrls[actionsComboBox.getSelectedIndex()])); } catch (URISyntaxException ex) { // TODO implement popup for error messages } } }); final JButton btnUSERNAMES = new JButton("Usernames"); btnUSERNAMES.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { createAndShowDacsUsernameFrame(); } }); final JButton btnLOGIN = new JButton("Login"); btnLOGIN.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { createAndShowLoginFrame(); } }); final JButton btnNAT = new JButton("NATs"); btnNAT.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { createAndShowDacsNatFrame(); } }); Container container = this.getContentPane(); actionsComboBox = new JComboBox(actions); actionsComboBox.setToolTipText("Select an Action"); actionsComboBox.setEditable(true); actionsComboBox.setSelectedIndex(0); JLabel actionLabel = new JLabel("Action:"); urlTextField = new TextField(70); urlTextField.setEditable(true); gotoUrlPanel.add(urlTextField); gotoUrlPanel.add(btnGOTO); actionPanel.add(actionLabel); actionPanel.add(actionsComboBox); actionPanel.add(btnGO); actionPanel.add(btnLOGIN); actionPanel.add(btnUSERNAMES); actionPanel.add(btnNAT); mainPanel.add(gotoUrlPanel, BorderLayout.NORTH); mainPanel.add(actionPanel, BorderLayout.SOUTH); modifiersPanel.add(checkOnlyCheckBox); modifiersPanel.add(enableEventHandlingCheckBox); JSplitPane splitInputPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mainPanel, modifiersPanel); splitInputPane.setOneTouchExpandable(false); responseTextArea = new JTextArea(); responseTextArea.setEditable(false); responseTextArea.setCaretPosition(0); htmlPane = new JEditorPane(); // htmlPane.setContentType("image/png"); htmlPane.setEditable(false); JSplitPane splitResponsePane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(responseTextArea), new JScrollPane(htmlPane)); splitResponsePane.setOneTouchExpandable(false); splitResponsePane.setResizeWeight(0.35); container.setLayout(new BorderLayout()); container.add(splitInputPane, BorderLayout.NORTH); container.add(splitResponsePane, BorderLayout.CENTER); }
From source file:fedroot.dacs.swingdemo.DemoFrame.java
/** * /*from ww w .j ava2 s . c o m*/ * @param dacsClientContext * @param feduri * @throws java.lang.Exception */ public DemoFrame(DacsClientContext dacsClientContext, Federation federation) throws Exception { logger.log(Level.INFO, "Federation {0}", federation.getFederationName()); this.federation = federation; this.dacsClientContext = dacsClientContext; // this.dacsClientContext.setDacs902EventHandler(federation, new Event902Handler(this)); // this.dacsClientContext.setDacs905EventHandler(federation, new Event905Handler(this)); JPanel mainPanel = new JPanel(new BorderLayout()); JPanel gotoUrlPanel = new JPanel(new FlowLayout()); JPanel actionPanel = new JPanel(new FlowLayout()); JPanel modifiersPanel = new JPanel(new FlowLayout()); /** Enable/Disable DACS Check_only mode */ checkOnlyCheckBox = new JCheckBox("Enable DACS Check Only", false); checkOnlyCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (checkOnlyCheckBox.isSelected()) { enableEventHandlingCheckBox.setSelected(false); enableEventHandlingCheckBox.setEnabled(false); } else { enableEventHandlingCheckBox.setEnabled(true); } } }); /** Enable/Disable Event Handling */ enableEventHandlingCheckBox = new JCheckBox("Enable Event Handling", false); final JButton btnGOTO = new JButton("Goto URL"); btnGOTO.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { followUrl(new URI(urlTextField.getText().trim())); } catch (URISyntaxException ex) { // TODO implement popup for error messages } } }); final JButton btnGO = new JButton("GO"); btnGO.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { followUrl(new URI(actionUrls[actionsComboBox.getSelectedIndex()])); } catch (URISyntaxException ex) { // TODO implement popup for error messages } } }); final JButton btnUSERNAMES = new JButton("Usernames"); btnUSERNAMES.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { createAndShowDacsUsernameFrame(); } }); final JButton btnLOGIN = new JButton("Login"); btnLOGIN.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { createAndShowLoginFrame(); } }); final JButton btnNAT = new JButton("NATs"); btnNAT.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { createAndShowDacsNatFrame(); } }); Container container = this.getContentPane(); actionsComboBox = new JComboBox(actions); actionsComboBox.setToolTipText("Select an Action"); actionsComboBox.setEditable(true); actionsComboBox.setSelectedIndex(0); JLabel actionLabel = new JLabel("Action:"); urlTextField = new TextField(70); urlTextField.setEditable(true); gotoUrlPanel.add(urlTextField); gotoUrlPanel.add(btnGOTO); actionPanel.add(actionLabel); actionPanel.add(actionsComboBox); actionPanel.add(btnGO); actionPanel.add(btnLOGIN); actionPanel.add(btnUSERNAMES); actionPanel.add(btnNAT); mainPanel.add(gotoUrlPanel, BorderLayout.NORTH); mainPanel.add(actionPanel, BorderLayout.SOUTH); modifiersPanel.add(checkOnlyCheckBox); modifiersPanel.add(enableEventHandlingCheckBox); JSplitPane splitInputPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mainPanel, modifiersPanel); splitInputPane.setOneTouchExpandable(false); responseTextArea = new JTextArea(); responseTextArea.setEditable(false); responseTextArea.setCaretPosition(0); htmlPane = new JEditorPane(); // htmlPane.setContentType("image/png"); htmlPane.setEditable(false); JSplitPane splitResponsePane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(responseTextArea), new JScrollPane(htmlPane)); splitResponsePane.setOneTouchExpandable(false); splitResponsePane.setResizeWeight(0.35); container.setLayout(new BorderLayout()); container.add(splitInputPane, BorderLayout.NORTH); container.add(splitResponsePane, BorderLayout.CENTER); }
From source file:TextComponentDemo.java
public TextComponentDemo() { super("TextComponentDemo"); //Create the text pane and configure it. textPane = new JTextPane(); textPane.setCaretPosition(0);// w w w. j a v a 2 s . c om textPane.setMargin(new Insets(5, 5, 5, 5)); StyledDocument styledDoc = textPane.getStyledDocument(); if (styledDoc instanceof AbstractDocument) { doc = (AbstractDocument) styledDoc; doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS)); } else { System.err.println("Text pane's document isn't an AbstractDocument!"); System.exit(-1); } JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(200, 200)); //Create the text area for the status log and configure it. changeLog = new JTextArea(5, 30); changeLog.setEditable(false); JScrollPane scrollPaneForLog = new JScrollPane(changeLog); //Create a split pane for the change log and the text area. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog); splitPane.setOneTouchExpandable(true); //Create the status area. JPanel statusPane = new JPanel(new GridLayout(1, 1)); CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status"); statusPane.add(caretListenerLabel); //Add the components. getContentPane().add(splitPane, BorderLayout.CENTER); getContentPane().add(statusPane, BorderLayout.PAGE_END); //Set up the menu bar. createActionTable(textPane); JMenu editMenu = createEditMenu(); JMenu styleMenu = createStyleMenu(); JMenuBar mb = new JMenuBar(); mb.add(editMenu); mb.add(styleMenu); setJMenuBar(mb); //Add some key bindings. addBindings(); //Put the initial text into the text pane. initDocument(); //Start watching for undoable edits and caret changes. doc.addUndoableEditListener(new MyUndoableEditListener()); textPane.addCaretListener(caretListenerLabel); doc.addDocumentListener(new MyDocumentListener()); }
From source file:TextComponentDemo.java
public TextComponentDemo() { super("TextComponentDemo"); // Create the text pane and configure it. textPane = new JTextPane(); textPane.setCaretPosition(0);/*from ww w . j a va 2 s .com*/ textPane.setMargin(new Insets(5, 5, 5, 5)); StyledDocument styledDoc = textPane.getStyledDocument(); if (styledDoc instanceof AbstractDocument) { doc = (AbstractDocument) styledDoc; doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS)); } else { System.err.println("Text pane's document isn't an AbstractDocument!"); System.exit(-1); } JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(200, 200)); // Create the text area for the status log and configure it. changeLog = new JTextArea(5, 30); changeLog.setEditable(false); JScrollPane scrollPaneForLog = new JScrollPane(changeLog); // Create a split pane for the change log and the text area. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scrollPane, scrollPaneForLog); splitPane.setOneTouchExpandable(true); // Create the status area. JPanel statusPane = new JPanel(new GridLayout(1, 1)); CaretListenerLabel caretListenerLabel = new CaretListenerLabel("Caret Status"); statusPane.add(caretListenerLabel); // Add the components. getContentPane().add(splitPane, BorderLayout.CENTER); getContentPane().add(statusPane, BorderLayout.PAGE_END); // Set up the menu bar. actions = createActionTable(textPane); JMenu editMenu = createEditMenu(); JMenu styleMenu = createStyleMenu(); JMenuBar mb = new JMenuBar(); mb.add(editMenu); mb.add(styleMenu); setJMenuBar(mb); // Add some key bindings. addBindings(); // Put the initial text into the text pane. initDocument(); textPane.setCaretPosition(0); // Start watching for undoable edits and caret changes. doc.addUndoableEditListener(new MyUndoableEditListener()); textPane.addCaretListener(caretListenerLabel); doc.addDocumentListener(new MyDocumentListener()); }