List of usage examples for javax.swing JTextPane setForeground
@BeanProperty(preferred = true, visualUpdate = true, description = "The foreground color of the component.") public void setForeground(Color fg)
From source file:StylesExample5.java
public static void main(String[] args) { try {/*from w w w .j a va 2 s .c o m*/ UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception evt) { } JFrame f = new JFrame("Styles Example 5"); // Create the StyleContext, the document and the pane StyleContext sc = new StyleContext(); final DefaultStyledDocument doc = new DefaultStyledDocument(sc); final JTextPane pane = new JTextPane(doc); // Create and add the style final Style heading2Style = sc.addStyle("Heading2", null); heading2Style.addAttribute(StyleConstants.Foreground, Color.red); heading2Style.addAttribute(StyleConstants.FontSize, new Integer(16)); heading2Style.addAttribute(StyleConstants.FontFamily, "serif"); heading2Style.addAttribute(StyleConstants.Bold, new Boolean(true)); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { try { // Add the text to the document doc.insertString(0, text, null); // Finally, apply the style to the heading doc.setParagraphAttributes(0, 1, heading2Style, false); // Set the foreground and font pane.setForeground(Color.blue); pane.setFont(new Font("serif", Font.PLAIN, 12)); } catch (BadLocationException e) { } } }); } catch (Exception e) { System.out.println("Exception when constructing document: " + e); System.exit(1); } f.getContentPane().add(new JScrollPane(pane)); f.setSize(400, 300); f.setVisible(true); }
From source file:Main.java
private static Component blackJTextPane() { JTextPane pane = new JTextPane(); pane.setBackground(Color.BLACK); pane.setForeground(Color.WHITE); pane.setText("Here is example text"); return pane;//from w w w. ja v a 2 s . c om }
From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java
public JTextPane createJTextPane(String text) { JTextPane jtp = new JTextPane(); jtp.setText(text);//from w ww . j a v a 2s . c o m SimpleAttributeSet underline = new SimpleAttributeSet(); StyleConstants.setUnderline(underline, true); jtp.getStyledDocument().setCharacterAttributes(0, text.length(), underline, true); jtp.setEditable(false); jtp.setOpaque(false); jtp.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 10)); jtp.setBorder(BorderFactory.createEmptyBorder()); jtp.setForeground(Color.blue); jtp.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); return jtp; }
From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java
/** * Setup the General Tab Pane/*from ww w. ja v a2 s. co m*/ * * @return JPanel for pane */ private JPanel setupGeneralTab() { JPanel generalTab = new JPanel(); generalTab.setLayout(new BorderLayout()); /* -- Create Main Panels -- */ JPanel centerPanel = new JPanel(); JPanel northPanel = new JPanel(); JPanel southPanel = new JPanel(); generalTab.add(centerPanel, BorderLayout.CENTER); generalTab.add(northPanel, BorderLayout.NORTH); /* -- Create Center Contents -- */ // Statistics Panel JPanel statsPanel = setupStatsPanel(); // Log Panel JPanel logPanel = new JPanel(); logPanel.setLayout(new BorderLayout()); logPanel.setBorder(BorderFactory.createTitledBorder("Log Output")); JTextPane logTextPane = new JTextPane(); logTextPane.setEditable(false); logTextPane.setBackground(Color.BLACK); logTextPane.setForeground(Color.WHITE); logPanel.add(new JScrollPane(logTextPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER); addUIElement("general.log", logTextPane); // Add to component map JPanel logOptionsPanel = new JPanel(); logPanel.add(logOptionsPanel, BorderLayout.SOUTH); logOptionsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); final JCheckBox logScrollCheckbox = new JCheckBox("Auto-Scroll Log"); logScrollCheckbox.setSelected(true); logScrollCheckbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JTextPaneAppender.setAutoScroll(logScrollCheckbox.isSelected()); } }); logOptionsPanel.add(logScrollCheckbox); // Enable Logging JTextPaneAppender.setTextPane(logTextPane); centerPanel.setLayout(new BorderLayout(10, 10)); centerPanel.add(statsPanel, BorderLayout.NORTH); centerPanel.add(logPanel, BorderLayout.CENTER); /* -- Create Buttons (South) -- */ generalTab.add(southPanel, BorderLayout.SOUTH); final JButton shutdownButton = new JButton("Shutdown"); shutdownButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doShutdownCluster(); } }); southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10)); southPanel.add(shutdownButton); addUIElement("general.shutdown", shutdownButton); // Add to components map return generalTab; }
From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java
/** * Setup General (Control Center) Tab// www . j av a 2 s.c om * * @return JPanel for Control Center */ private JPanel setupGeneral() { JPanel generalPanel = new JPanel(); generalPanel.setLayout(new BorderLayout()); /* -- Stats Panel -- */ JPanel statsPanel = new JPanel(); generalPanel.add(statsPanel, BorderLayout.NORTH); statsPanel.setLayout(new GridLayout(0, 2, 10, 10)); JPanel eastPanel = new JPanel(); statsPanel.add(eastPanel, BorderLayout.EAST); eastPanel.setLayout(new BorderLayout()); JPanel westPanel = new JPanel(); statsPanel.add(westPanel, BorderLayout.WEST); westPanel.setLayout(new BorderLayout()); // Grid Information Panel JPanel gridInfoPanel = new JPanel(); eastPanel.add(gridInfoPanel, BorderLayout.NORTH); gridInfoPanel.setBorder(BorderFactory.createTitledBorder("Grid Information")); gridInfoPanel.setLayout(new GridLayout(0, 2, 10, 10)); JLabel nodeIdLabel = new JLabel("Node ID :"); gridInfoPanel.add(nodeIdLabel); JLabel nodeId = new JLabel("#nodeid#"); gridInfoPanel.add(nodeId); addUIElement("general.stats.nodeid", nodeId); // Add to components map JLabel nodeIpLabel = new JLabel("Node IP :"); gridInfoPanel.add(nodeIpLabel); JLabel nodeIp = new JLabel("#nodeip#"); gridInfoPanel.add(nodeIp); addUIElement("general.stats.nodeip", nodeIp); // Add to components map JLabel clusterIdLabel = new JLabel("Cluster ID :"); gridInfoPanel.add(clusterIdLabel); JLabel clusterId = new JLabel("#clusterid#"); gridInfoPanel.add(clusterId); addUIElement("general.stats.clusterid", clusterId); // Add to components map JLabel clusterServiceLabel = new JLabel("Cluster Service :"); gridInfoPanel.add(clusterServiceLabel); JLabel clusterService = new JLabel("#clusterservice#"); gridInfoPanel.add(clusterService); addUIElement("general.stats.clusterservice", clusterService); // Add to components map // Node Status Panel JPanel nodeStatusPanel = new JPanel(); eastPanel.add(nodeStatusPanel, BorderLayout.SOUTH); nodeStatusPanel.setBorder(BorderFactory.createTitledBorder("GridNode Status")); nodeStatusPanel.setLayout(new GridLayout(0, 2, 10, 10)); JLabel statusLabel = new JLabel("Status :"); nodeStatusPanel.add(statusLabel); JLabel status = new JLabel("#status#"); nodeStatusPanel.add(status); addUIElement("general.stats.status", status); // Add to components map JLabel uptimeLabel = new JLabel("Node Up Time :"); nodeStatusPanel.add(uptimeLabel); JLabel uptime = new JLabel("#uptime#"); nodeStatusPanel.add(uptime); addUIElement("general.stats.uptime", uptime); // Add to components map JLabel execTimeLabel = new JLabel("Execution Time :"); nodeStatusPanel.add(execTimeLabel); JLabel execTime = new JLabel("#exectime#"); nodeStatusPanel.add(execTime); addUIElement("general.stats.exectime", execTime); // Add to components map // Execution Statistics Panel JPanel execStatsPanel = new JPanel(); westPanel.add(execStatsPanel, BorderLayout.NORTH); execStatsPanel.setLayout(new GridLayout(0, 2, 10, 10)); execStatsPanel.setBorder(BorderFactory.createTitledBorder("Execution Statistics")); JLabel totalJobsLabel = new JLabel("Total Jobs :"); execStatsPanel.add(totalJobsLabel); JLabel totalJobs = new JLabel("0"); execStatsPanel.add(totalJobs); addUIElement("general.stats.totaljobs", totalJobs); // Add to components map JLabel totalTasksLabel = new JLabel("Total Tasks :"); execStatsPanel.add(totalTasksLabel); JLabel totalTasks = new JLabel("0"); execStatsPanel.add(totalTasks); addUIElement("general.stats.totaltasks", totalTasks); // Add to components map JLabel totalBansLabel = new JLabel("Banments :"); execStatsPanel.add(totalBansLabel); JLabel totalBans = new JLabel("0"); execStatsPanel.add(totalBans); addUIElement("general.stats.totalbans", totalBans); // Add to components map // Execution Active Job Panel JPanel activeJobPanel = new JPanel(); westPanel.add(activeJobPanel, BorderLayout.SOUTH); activeJobPanel.setLayout(new GridLayout(0, 2, 10, 10)); activeJobPanel.setBorder(BorderFactory.createTitledBorder("Active Job")); JLabel jobNameLabel = new JLabel("GridJob Name :"); activeJobPanel.add(jobNameLabel); JLabel jobName = new JLabel("#jobname#"); activeJobPanel.add(jobName); addUIElement("general.stats.jobname", jobName); // Add to components map JLabel durationLabel = new JLabel("Duration :"); activeJobPanel.add(durationLabel); JLabel duration = new JLabel("#duration#"); activeJobPanel.add(duration); addUIElement("general.stats.duration", duration); // Add to components map JLabel tasksLabel = new JLabel("Tasks Executed :"); activeJobPanel.add(tasksLabel); JLabel tasks = new JLabel("#xyz#"); activeJobPanel.add(tasks); addUIElement("general.stats.tasks", tasks); // Add to components map JLabel failuresLabel = new JLabel("Failures :"); activeJobPanel.add(failuresLabel); JLabel failures = new JLabel("#failures#"); activeJobPanel.add(failures); addUIElement("general.stats.failures", failures); // Add to components map /* -- Log Panel -- */ JPanel logPanel = new JPanel(); generalPanel.add(logPanel, BorderLayout.CENTER); logPanel.setLayout(new BorderLayout()); logPanel.setBorder(BorderFactory.createTitledBorder("Log Output")); JTextPane logTextPane = new JTextPane(); logTextPane.setEditable(false); logTextPane.setBackground(Color.BLACK); logTextPane.setForeground(Color.WHITE); logPanel.add(new JScrollPane(logTextPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER); addUIElement("general.log", logTextPane); // Add to component map JPanel logOptionsPanel = new JPanel(); logPanel.add(logOptionsPanel, BorderLayout.SOUTH); logOptionsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); final JCheckBox logScrollCheckbox = new JCheckBox("Auto-Scroll Log"); logScrollCheckbox.setSelected(true); logScrollCheckbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JTextPaneAppender.setAutoScroll(logScrollCheckbox.isSelected()); } }); logOptionsPanel.add(logScrollCheckbox); // Enable Logging JTextPaneAppender.setTextPane(logTextPane); /* -- Buttons Panel -- */ JPanel buttonsPanel = new JPanel(); generalPanel.add(buttonsPanel, BorderLayout.SOUTH); buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); // Shutdown Button JButton shutdownButton = new JButton("Shutdown"); buttonsPanel.add(shutdownButton); shutdownButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doShutdownNode(); } }); // Start Up time Thread Thread t = new Thread(new Runnable() { public void run() { long start = System.currentTimeMillis(); while (true) { try { Thread.sleep(1000); } catch (InterruptedException e) { log.warn("Interrupted Exception in Up Time Thread", e); } final String uptime = TimeUtils.timeDifference(start); SwingUtilities.invokeLater(new Runnable() { public void run() { JLabel upTime = getUIElement("general.stats.uptime"); upTime.setText(uptime); } }); } } }); t.setDaemon(true); t.start(); // Auto-Discovery Thread Thread autoDiscovery = new Thread(new Runnable() { public void run() { while (true) { try { // Attempt every 30 seconds Thread.sleep(30000); } catch (InterruptedException e) { log.warn("Interrupted Exception in Up Time Thread", e); } if (autodiscover && (!Grid.isNode())) { // 30 Second Intervals doDiscover(true); } } } }); autoDiscovery.setDaemon(true); autoDiscovery.start(); return generalPanel; }
From source file:org.owasp.jbrofuzz.fuzz.ui.FuzzingPanel.java
private JTextPane createEditablePane() { JTextPane textPane = new JTextPane(); // Get the preferences for wrapping lines of text final boolean wrapText = JBroFuzz.PREFS.getBoolean(JBroFuzzPrefs.FUZZING[2].getId(), false); if (wrapText) { textPane = new JTextPane(); } else {//from w w w . jav a 2s .c om textPane = new NonWrappingTextPane(); } textPane.putClientProperty("charset", "UTF-8"); textPane.setEditable(true); textPane.setVisible(true); textPane.setFont(new Font("Verdana", Font.PLAIN, 12)); textPane.setMargin(new Insets(1, 1, 1, 1)); textPane.setBackground(Color.WHITE); textPane.setForeground(Color.BLACK); // Set the editor kit responsible for highlighting textPane.setEditorKit(new StyledEditorKit() { private static final long serialVersionUID = -6085642347022880064L; public Document createDefaultDocument() { return new TextHighlighter(); } }); // Right click: Cut, Copy, Paste, Select All RightClickPopups.rightClickRequestTextComponent(this, textPane); return textPane; }
From source file:org.owasp.jbrofuzz.fuzz.ui.FuzzingPanel.java
JTextPane createSimplePane() { JTextPane textPane = new JTextPane(); textPane.setMargin(new Insets(1, 1, 1, 1)); textPane.setBackground(Color.WHITE); textPane.setForeground(Color.BLACK); return textPane; }