Multiple Fonts in a javax.swing.JTextPane

I am trying to use multiple fonts in a JTextPane, but can only find ways of changing the font family used. Can anyone give me any pointers on how to do this, or a document somewhere that explains, either way with out going into the javax.swing.text.html, javax.swing.text.html.parser or java.awt.font packages.
Any information that can be provided would be appreciated.
Thanks,
Nathan

Just use SimpleAttributeSet like :
SimpleAttributeSet defaultSet = new SimpleAttributeSet();
        StyleConstants.setForeground( defaultSet, Color.BLACK );
        StyleConstants.setFontFamily( defaultSet, "Verdana" );
        StyleConstants.setFontSize( defaultSet, 14 );
        SimpleAttributeSet navigationSet = new SimpleAttributeSet();
        StyleConstants.setForeground( navigationSet, new Color(00, 99, 00) );
        StyleConstants.setBold( navigationSet, true );
        StyleConstants.setFontFamily( navigationSet, "Verdana" );
        StyleConstants.setFontSize( navigationSet, 11 );
// just defiine endPoints what ever you want
((DefaultStyledDocument)textPane.getDocument()).setCharacterAttributes(0, endPoint1, defaultSet , true)
((DefaultStyledDocument)textPane.getDocument()).setCharacterAttributes(0, endPoint2, navigation , true)

Similar Messages

  • Javax.swing.JTextPane - COLOR Problem

    Hi
    I am using javax.swing.JTextPane object to display text recieved from two servers.
    How can I make messages recieved from Server 1 to be in RED and while from Server 2
    to be in Green? i.e. the window should look...
    (red) Server 1 says ta ta
    (green) Server 2 says Hello
    My code looks....
    javax.swing.JTextPane WINDOW;
    String message1 = connection1.getMessage();
    ..........// What code should I put here??? to make this message look RED??
    ..........// Color of previous text should remain as it is...
    WINDOW.setText(WINDOW.getText() + message1);An Example would be highly appreciated.
    Regards
    Fahad

    Hi,
    that is the wrong way - try this method in your JTextPane subclass
    public void appendText(String s,Color col) {
    StyledDocument sd = getStyledDocument();
    SimpleAttributeSet attr = new SimpleAttributeSet();
    StyleConstants.setForground(attr,col);
    try { sd.insertString(sd.getLength(),s,attr); }
    catch (BadLocationException e) {}
    } // end of methodand use it in your code like that
    WINDOW.appendText(message1,Color.red);
    hope that helps
    greetings Marsian

  • Working with objects \ beans inside a Swing.JTextPane

    javax.swing.text.html
    specifically
    javax.swing.text.html.ObjectVeiw Class
    Is it possible to set the size of on object, which is an instance of type Component
    Example
    Although these beans work fine, I can not set the width and height properties while they are embedded in the JTextPane. Attempts to give initial values of height & width within the object tag also fail.
    <HTML><BODY bgcolor="#00A0A0">
    Test This <P>page
    <p>This next object is a Simple Bean that extends Canvas
    <object classid="SimpleBean" width="150" height="150">
    <param name="width" value="10">               <! Does not work in JTextPane>
    <param name="height" value="200">     
    <param name="underText" value="Text for the Canvas">
    </object>
    <p>This next object is a JTextPane
    <object classid="javax.swing.JTextPane">
    <param name="text" value="Embeded JTextPane">
    <param name="size" value"150,150">
    </object>
    </BODY></HTML>
    Also could you show me more HTML examples of use

    if there is
    a LayoutManager in use, it will overwrite the size you
    attempt to set. Only if the layout manager is null
    will doing a setSize() work properly.true

  • Multiple font colors

    what's up
    does anybody know how to display font in multiple colors in a Jtextarea or another text component every time i change the font color in my jtextarea it changes for all the words i want it to change for only the next words that i type.
    thanks

    the following sample might be useful to u. i am not sure whether this works for textarea.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class test extends JApplet
         private JTextPane pane;
         private JButton colors;
         private JToolBar tb;
         public void init()
              pane = new JTextPane();
              tb = new JToolBar(JToolBar.HORIZONTAL);
              colors=new JButton("Colors");
              colors.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        Color newColor = javax.swing.JColorChooser.showDialog(null,"Choose Text Color",Color.cyan);     
                                  if(newColor!=null){
                                            MutableAttributeSet attr = new SimpleAttributeSet();
                                            StyleConstants.setForeground(attr,newColor);
                                            pane.setCharacterAttributes(attr,false);
              tb.add(colors);
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(tb,"North");
              getContentPane().add(pane,"Center");
    //<applet code=test.class width=300 height=300></applet>
    for more information follow this link.
    http://manning.spindoczine.com/sbe/files/uts2/Chapter20html/Chapter20.htm
    cheers
    sri

  • Variable textArea not found in class javax.swing.JFrame...

    Making progress on this issue -- but still stuck. Again trying to get the text from a JTextArea on exit:
            frame.addWindowListener
           (new WindowAdapter() {
             public void windowClosing(WindowEvent e)
                System.out.println("Why me???" + frame.textArea.getText());
            });User MARSIAN helped me understand the scope fo the variables and now that has been fixed. Unfortunately I cannot access my variable textArea in the above code. If get this error:
    Error: variable textArea not found in class javax.swing.JFrame
    What am I doing wrong?
    import  java.net.*;
    import  javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import FragImpl.*;
    public class Framework extends WindowAdapter {
        public int numWindows = 0;
        private Point lastLocation = null;
        private int maxX = 500;
        private int maxY = 500;
        JFrame frame;
        public Framework() {
            newFrag();
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            maxX = screenSize.width - 50;
            maxY = screenSize.height - 50;
            makeNewWindow();
        public void makeNewWindow() {
            frame = new MyFrame(this);  //*
            numWindows++;
            System.out.println("Number of windows: " + numWindows);
            if (lastLocation != null) {
                //Move the window over and down 40 pixels.
                lastLocation.translate(40, 40);
                if ((lastLocation.x > maxX) || (lastLocation.y > maxY)) {
                    lastLocation.setLocation(0, 0);
                frame.setLocation(lastLocation);
            } else {
                lastLocation = frame.getLocation();
            System.out.println("Frame location: " + lastLocation);
            frame.setVisible(true);
            frame.addWindowListener
           (new WindowAdapter() {
             public void windowClosing(WindowEvent e)
                System.out.println("Why me???" + frame.textArea.getText());
        //This method must be evoked from the event-dispatching thread.
        public void quit(JFrame frame) {
            if (quitConfirmed(frame)) {
                System.exit(0);
            System.out.println("Quit operation not confirmed; staying alive.");
        private boolean quitConfirmed(JFrame frame) {
            String s1 = "Quit";
            String s2 = "Cancel";
            Object[] options = {s1, s2};
            int n = JOptionPane.showOptionDialog(frame,
                    "Windows are still open.\nDo you really want to quit?",
                    "Quit Confirmation",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE,
                    null,
                    options,
                    s1);
            if (n == JOptionPane.YES_OPTION) {
                return true;
            } else {
                return false;
         private void newFrag()
              Frag frag = new FragImpl();
        public static void main(String[] args) {
            Framework framework = new Framework();
    class MyFrame extends JFrame {
        protected Dimension defaultSize = new Dimension(200, 200);
        protected Framework framework = null;
        private Color color = Color.yellow;
        private Container c;
        JTextArea textArea;
        public MyFrame(Framework controller) {
            super("New Frame");
            framework = controller;
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            setSize(defaultSize);
            //Create a text area.
            textArea = new JTextArea(
                    "This is an editable JTextArea " +
                    "that has been initialized with the setText method. " +
                    "A text area is a \"plain\" text component, " +
                    "which means that although it can display text " +
                    "in any font, all of the text is in the same font."
            textArea.setFont(new Font("Serif", Font.ITALIC, 16));
            textArea.setLineWrap(true);
            textArea.setWrapStyleWord(true);
            textArea.setBackground ( Color.yellow );
            JScrollPane areaScrollPane = new JScrollPane(textArea);
            //Create the status area.
            JPanel statusPane = new JPanel(new GridLayout(1, 1));
            ImageIcon icoOpen = null;
            URL url = null;
            try
                icoOpen = new ImageIcon("post_it0a.gif"); //("doc04d.gif");
            catch(Exception ex)
                ex.printStackTrace();
                System.exit(1);
            setIconImage(icoOpen.getImage());
            c = getContentPane();
            c.setBackground ( Color.yellow );
            c.add ( areaScrollPane, BorderLayout.CENTER )  ;
            c.add ( statusPane, BorderLayout.SOUTH );
            c.repaint ();
    }

    Yeah!!! It works. Turned out to be a combination of DrKlap's and Martisan's suggestions -- had to change var frame's declaration from JFrame to MyFrame:
        MyFrame frame;Next, created the external class -- but again changed JFrame references to MyFrame:
    public class ShowOnExit extends WindowAdapter {
    //   JFrame aFrame;
       MyFrame aFrame;
       public ShowOnExit(MyFrame f) {
          aFrame = f;
       public void windowClosing(WindowEvent e)
          System.out.println("Why me???" + aFrame.textArea.getText()); // aFrame here not frame !!!
    }This worked. So looks like even though the original code added a WindowListener to 'frame', the listener didn't couldn't access frame's methods unless it was explicitly passed in as a parameter. Let me know if that's wrong.
    Thanks again, all.

  • Urgent :Using a font face name in a JtextPane

    1)How can I use a font face name for setting the font of the text I display in a JTextPane.A call to textPane.setFont() does not work I could find a method StyleConstants.setFontFamily() , but , if I'm not wrong, that would set the font family only and hence the valid arguments to the method would be family names like "Serif", "SansSerif", "Monospaced", "Dialog", and "DialogInput", and not a facename like "Courier".
    2) Also because I cannot use a java.awt.Font object for JTextPane, I cannot use a cache for fonts so that I can share a Font object across multiple JTextPanes. Any ideas?
    Regards
    Nikhil.

    I am not sure how to answer this because you do not
    make it clear why you cannot use a
    java.awt.Font.The reason for this is that if I invoke method setFont (java.awt.Font) on a JTextPane , it has no effect.
    The only way I could find for setting a font in JTextPane is to use StyleConstants.setFontFamily() which
    takes a font family name as a string. As a result , if I have multiple JTextPanes with the same font,
    I'm not sure if internally some sort of caching would be used by the java runtime.
    If only I could use setFont(java.awt.Font) ona JTextPane, I could have cached java.awt.Font objects
    and supplied the same Font object in setFont(java.awt.Font) method of all the JTextPanes that have
    text with identical fonts.
    If you define a
    java.awt.Font in a high-level class, and pass
    it to many JTextPanes it will only be cached once,
    because of oblique passing-by-reference used by the
    JVM.

  • Question to understand javax.swing.plaf.FontUIResource("Arial Unicode MS"..

    Hi Commuity!
    I have an Question about this function!
    javax.swing.plaf.FontUIResource("Arial Unicode MS", Font.PLAIN, 12);
    I have read the Java doc but this didn�t help!
    I wanted to know, what happend, if this Font is not an the Client.
    So i deleted the Font "Arial Unicode MS".
    But the applikation still use this Font. But it is not on my local PC?
    Were do Swing load the Font�s from?
    Are the Fonts included in Java?
    thx a lot
    Florian

    Has got nobody an idea, where swing load the fonts from?

  • Swing---JTextPane(a boring trouble---looking forward to answer)

    In the following program the JLabel inherited can'nt be seen when it inserted into the JTextPane, I wander why?
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class AdvancedJTextPane extends JFrame
    JTextPane jtp;
    public AdvancedJTextPane(){
         jtp=new JTextPane();
         this.getContentPane().setLayout(new BorderLayout());
         JScrollPane js = new JScrollPane();
         js.getViewport().add(jtp);
         this.getContentPane().add(js);
         this.pack();
         this.setSize(350, 250);
         this.setVisible(true);
         jtp.insertComponent(new DrawLabel(""));
         this.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    System.exit(0);
    public static void main(String[] args) {
    new AdvancedJTextPane();
    class DrawLabel extends JLabel {
    public DrawLabel(String label) {
    super(label);
    Dimension size = getPreferredSize();
    size.width = size.height = Math.max(size.width,
    size.height);
    setPreferredSize(size);
    protected void paintComponent(Graphics g) {
    g.setColor(Color.lightGray);
    g.drawOval(0, 0, getSize().width-3, getSize().height-3);
    super.paintComponent(g);
    protected void paintBorder(Graphics g) {
    g.setColor(getForeground());
    g.drawOval(0, 0, getSize().width-1, getSize().height-1);
    }

    Here's your culprit:
    jtp.insertComponent(new DrawLabel(""));You need to use something other than an empty string (spaces will work):
    jtp.insertComponent(new DrawLabel("     "));

  • [HELP! ] why my program thows a javax.swing.text.ChangedCharSetException?

    there's the source:
    import java.io.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import javax.swing.border.*;
    class HTMLMagician extends JFrame
         protected static final String APP_NAME="HTML Magician V1.0 Produced By V Studio";
         protected JTextPane hm_textPane;
         protected StyleSheet hm_styleSheet;
         protected HTMLEditorKit html_kit;
         protected HTMLDocument html_document;
         protected JMenuBar hm_menuBar;
         protected JToolBar hm_toolBar;
         protected JFileChooser hm_fileChooser;
         protected File current_file;
         protected boolean text_changed=false;
         public HTMLMagician()
              super(APP_NAME);
              setSize(800,600);
              getContentPane().setLayout(new BorderLayout());
              produceMenuBar();
              hm_textPane=new JTextPane();
              html_kit=new HTMLEditorKit();
              hm_textPane.setEditorKit(html_kit);
              JScrollPane textPane_scrollPane=new JScrollPane();
              textPane_scrollPane.getViewport().add(hm_textPane);
              getContentPane().add(textPane_scrollPane,BorderLayout.CENTER);
              hm_fileChooser=new JFileChooser();
              javax.swing.filechooser.FileFilter hm_filter=new javax.swing.filechooser.FileFilter()
                   public boolean accept(File pathname)
                        if(pathname.isDirectory())
                             return true;
                        String ext_name=pathname.getName().toLowerCase();
                        if(ext_name.endsWith(".htm"))
                             return true;
                        if(ext_name.endsWith(".html"))
                             return true;
                        if(ext_name.endsWith(".asp"))
                             return true;
                        if(ext_name.endsWith(".jsp"))
                             return true;
                        if(ext_name.endsWith(".css"))
                             return true;
                        if(ext_name.endsWith(".php"))
                             return true;
                        if(ext_name.endsWith(".aspx"))
                             return true;
                        if(ext_name.endsWith(".xml"))
                             return true;
                        if(ext_name.endsWith(".txt"))
                             return true;
                        return false;
                   public String getDescription()
                        return "HTML files(*.htm,*.html,*.asp,*.jsp,*.css,*.php,*.aspx,*.xml)";
              hm_fileChooser.setAcceptAllFileFilterUsed(false);
              hm_fileChooser.setFileFilter(hm_filter);
              try
                   File dir=(new File(".")).getCanonicalFile();
                   hm_fileChooser.setCurrentDirectory(dir);
              }catch(IOException ex)
                   showError(ex,"Error openning current directory");
              newDocument();
              WindowListener action_winClose=new WindowAdapter()
                   public void windowClosing(WindowEvent evt)
                        if(!promptToSave())
                             return;
                        System.exit(0);
              addWindowListener(action_winClose);
              setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
              setVisible(true);
         protected void produceMenuBar()
              hm_menuBar=new JMenuBar();
              hm_toolBar=new JToolBar();
              JMenu menu_file=new JMenu("File");
              menu_file.setMnemonic('f');
              ImageIcon icon_new=new ImageIcon("imgs/file.gif");
              Action action_new=new AbstractAction("New",icon_new)
                   public void actionPerformed(ActionEvent evt)
                        if(!promptToSave())
                             return;
                        newDocument();
              JMenuItem item_new=new JMenuItem(action_new);
              item_new.setMnemonic('n');
              item_new.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK));
              menu_file.add(item_new);
              JButton button_new=hm_toolBar.add(action_new);
              ImageIcon icon_open=new ImageIcon("imgs/folder_open.gif");
              Action action_open=new AbstractAction("Open...",icon_open)
                   public void actionPerformed(ActionEvent evt)
                        if(!promptToSave())
                             return;
                        openDocument();
              JMenuItem item_open=new JMenuItem(action_open);
              item_open.setMnemonic('o');
              item_open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));
              menu_file.add(item_open);
              JButton button_open=hm_toolBar.add(action_open);
              ImageIcon icon_save=new ImageIcon("imgs/floppy.gif");
              Action action_save=new AbstractAction("Save",icon_save)
                   public void actionPerformed(ActionEvent evt)
                        saveAs(false);
              JMenuItem item_save=new JMenuItem(action_save);
              item_save.setMnemonic('s');
              item_save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
              menu_file.add(item_save);
              JButton button_save=hm_toolBar.add(action_save);
              Action action_saveAs=new AbstractAction("Save As...")
                   public void actionPerformed(ActionEvent evt)
                        saveAs(true);
              JMenuItem item_saveAs=new JMenuItem(action_saveAs);
              item_saveAs.setMnemonic('a');
              item_saveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.CTRL_MASK));
              menu_file.add(item_saveAs);
              menu_file.addSeparator();
              Action action_close=new AbstractAction("Quit")
                   public void actionPerformed(ActionEvent evt)
                        if(!promptToSave())
                             return;
                        System.exit(0);
              JMenuItem item_exit=new JMenuItem(action_close);
              item_exit.setMnemonic('q');
              item_exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,InputEvent.CTRL_MASK));
              menu_file.add(item_exit);
              hm_menuBar.add(menu_file);
              setJMenuBar(hm_menuBar);
              getContentPane().add(hm_toolBar,BorderLayout.NORTH);
         protected String getDocumentName()
              return current_file==null ? "Untitled" : current_file.getName();
         protected void newDocument()
              html_document=(HTMLDocument)html_kit.createDefaultDocument();
              hm_styleSheet=html_document.getStyleSheet();
              hm_textPane.setDocument(html_document);
              current_file=null;
              setTitle(getDocumentName()+" - "+APP_NAME);
              Runnable runner=new Runnable()
                   public void run()
                        text_changed=false;
                        html_document.addDocumentListener(new action_textChanged());
              SwingUtilities.invokeLater(runner);
         protected void openDocument()
              if(hm_fileChooser.showOpenDialog(HTMLMagician.this)!=JFileChooser.APPROVE_OPTION)
                   return;
              File f=hm_fileChooser.getSelectedFile();
              if(f==null || !f.isFile())
                   return;
              current_file=f;
              setTitle(getDocumentName()+" - "+APP_NAME);
              HTMLMagician.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
              try
                   InputStream in=new FileInputStream(current_file);
                   html_document=(HTMLDocument)html_kit.createDefaultDocument();
                   html_kit.read(in,html_document,0);
                   hm_styleSheet=html_document.getStyleSheet();
                   hm_textPane.setDocument(html_document);
                   in.close();
              }catch(Exception ex)
                   showError(ex,"Error openning file "+current_file);
              HTMLMagician.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
              Runnable runner=new Runnable()
                   public void run()
                        text_changed=false;
                        html_document.addDocumentListener(new action_textChanged());
              SwingUtilities.invokeLater(runner);
         protected boolean saveAs(boolean as)
              if(!as && !text_changed)
                   return true;
              if(as || current_file==null)
                   if(hm_fileChooser.showSaveDialog(HTMLMagician.this)!=JFileChooser.APPROVE_OPTION)
                        return false;
                   File f=hm_fileChooser.getSelectedFile();
                   if(f==null || !f.isFile())
                        return false;
                   current_file=f;
                   setTitle(getDocumentName()+" - "+APP_NAME);
              HTMLMagician.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
              try
                   OutputStream out=new FileOutputStream(current_file);
                   html_kit.write(out,html_document,0,html_document.getLength());
                   out.close();
              }catch(Exception ex)
                   showError(ex,"Error saving file "+current_file);
              HTMLMagician.this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
              return true;
         protected boolean promptToSave()
              if(!text_changed)
                   return true;
              int result=JOptionPane.showConfirmDialog(this,"Save change to "+getDocumentName(),APP_NAME,JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE);
              switch(result)
                   case JOptionPane.YES_OPTION:
                        if(!saveAs(false))
                             return false;
                        return true;
                   case JOptionPane.NO_OPTION:
                        return true;
                   case JOptionPane.CANCEL_OPTION:
                        return false;
              return true;
         protected void showError(Exception ex,String message)
              ex.printStackTrace();
              JOptionPane.showMessageDialog(this,message,APP_NAME,JOptionPane.WARNING_MESSAGE);
         public static void main(String[] args)
              new HTMLMagician();
         class action_textChanged implements DocumentListener
              public void changedUpdate(DocumentEvent evt)
                   text_changed=true;
              public void insertUpdate(DocumentEvent evt)
                   text_changed=true;
              public void removeUpdate(DocumentEvent evt)
                   text_changed=true;
    when i open a .html file,the command output :
    javax.swing.text.ChangedCharSetException
         at javax.swing.text.html.parser.DocumentParser.handleEmptyTag(Unknown Source)
         at javax.swing.text.html.parser.Parser.startTag(Unknown Source)
         at javax.swing.text.html.parser.Parser.parseTag(Unknown Source)
         at javax.swing.text.html.parser.Parser.parseContent(Unknown Source)
         at javax.swing.text.html.parser.Parser.parse(Unknown Source)
         at javax.swing.text.html.parser.DocumentParser.parse(Unknown Source)
         at javax.swing.text.html.parser.ParserDelegator.parse(Unknown Source)
         at javax.swing.text.html.HTMLEditorKit.read(Unknown Source)
         at javax.swing.text.DefaultEditorKit.read(Unknown Source)
         at HTMLMagician.openDocument(HTMLMagician.java:222)
         at HTMLMagician$4.actionPerformed(HTMLMagician.java:128)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at javax.swing.JComponent.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    why? what's wrong? thanks

    The DocumentParser seems to throw a ChangedCharSetException if it finds a "http-equiv" meta tag for "content-type" or "charset" and if the parser's "ignoreCharSet" property is set to false on creation.

  • Having multiple font styles in a menuitem

    I am just trying to apply different "font styles" to a menu item available in a menubar.Font style include the three parameters which is passed to a font constructor.
    Font(java.lang.String name, int style, int size).
    say i want to have a Font("Script",Font.BOLD,20) to a particular menu item which i have created using JMenuBar.
    this is the prob. exactly.
    needed valuable suggestions.(if possible the code)
    regards,
    Ranjit Singh

    Here's a possible Swing solution, if I understand you correctly:
    import java.awt.*;
    import javax.swing.*;
    public class Test
         public static void main(String args[])
              new Test();
         public Test()
              JFrame f = new JFrame("Menu Item Test");
              JMenuBar menu = new JMenuBar();
              JMenu menuFile = new JMenu("File");
              menu.add(menuFile);
              JMenuItem menuItemOpen = new JMenuItem("Open");
              menuItemOpen.setFont(new Font("Serif", Font.BOLD, 16));
              JMenuItem menuItemClose = new JMenuItem("Close");
              menuItemClose.setFont(new Font("Monospaced", Font.ITALIC, 14));
              JMenuItem menuItemExit = new JMenuItem("Exit");
              menuItemExit.setFont(new Font("Dialog", Font.ITALIC, 12));
              menuFile.add(menuItemOpen);
              menuFile.add(menuItemClose);
              menuFile.add(menuItemExit);
              f.setJMenuBar(menu);
              f.pack();
              f.show();
    }

  • Where did javax.swing.plaf.metal go after 1.4?

    Dear Users of the java.swing libraries,
    I've made a schoolproject in javax.swing and i am using the javax.swing.plaf.metal.MetalLookAndFeel as LookAndFeel.
    The Problem is: it seems sun has removed the Metal LookAndFeel in versions past 1.4 or something like that. I read this in the source DefaultmetalTheme.java file:
    * This class describes the default Metal Theme.
    * <p>
    * <strong>Warning:</strong>
    * Serialized objects of this class will not be compatible with
    * future Swing releases. The current serialization support is
    * appropriate for short term storage or RMI between applications running
    * the same version of Swing.  As of 1.4, support for long term storage
    * of all JavaBeans<sup><font size="-2">TM</font></sup>
    * has been added to the <code>java.beans</code> package.
    * Please see {@link java.beans.XMLEncoder}.
    * @version 1.25 01/23/03
    * @author Steve Wilson
    */Now i wonder, can i find this cool Metal style anywhere else? In like the java.beans that was mentioned in the code of DefaultmetalTheme.java.
    In my current situation my project is ruined and i would relly appriciate some feedback on this!
    Yours Truthfully,
    Alexander Thore

    They would only be where you put them.
    You should be importing them to your computer regularly as you would with any digital camera, most especially before any update.
    If you failed to do this, then they are likely gone.
    You can try a restore from backup.

  • Javax.swing

    hi.. i want to ask about how can i display my text in a scrollable window by importing javax.swing.*?

    yes like notepad.. thanks for the code.
    i already have this code in a file called display.java
    public static void display( String str )
    JTextArea textArea = new JTextArea( str, 15, 20 );
    textArea.setFont( new Font( "Serif", Font.PLAIN, 14 ));
    textArea.setForeground( Color.red );
    JScrollPane scrollPane= new JScrollPane( textArea );
    JOptionPane.showMessageDialog( null, scrollPane );
    and i have another file that perform a search string(search.java). i want the search result to be displayed in a scrollable windows. how can i do that? thanks..

  • Help ! inaccurate time recorded using javax.swing.timer

    Hi All,
    I am currently trying to write a stopwatch for timing application events such as loggon, save, exit ... for this I have created a simple Swing GUI and I am using the javax.swing.timer and updating a the time on a Jlabel. The trouble that I am having is that the time is out by up to 20 seconds over a 10 mins. Is there any way to get a more accruate time ?? The code that I am using is attached below.
    private Timer run = new Timer(1000, new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    timeTaken.setText("<html><font size = 5><b>" + (df.format(timeHours)) + ":" + (df.format(timeMins)) + ":"
    + (df.format(timeSeconds++)) + "</b></font><html>");
    receordedTimeValue = ((df.format(timeHours)) + ":" + (df.format(timeMins)) + ":"
    + (df.format(timeSeconds)));
    if (timeSeconds == 60) {
    timeMins++;
    timeSeconds = 0;
    if (timeMins == 60) {
    timeHours++;
    timeMins = 0;

    To get more accurate time you should use the System.currentTimeMillis() method.
    Try this code :
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CountUpLabel extends JLabel{
         javax.swing.Timer timer;
         long startTime, count;
         public CountUpLabel() {
              super(" ", SwingConstants.CENTER);
              timer = new javax.swing.Timer(500, new ActionListener() { // less than or equal to 1000 (1000, 500, 250,200,100) 
                   public void actionPerformed(ActionEvent event) {
                        if (startTime == -1) {          
                             count = 0;               
                             startTime = System.currentTimeMillis();
                        else {
                             count = System.currentTimeMillis()-startTime;
                        setText(getStringTime(count));
         private static final String getStringTime(long millis) {
              int seconds = (int)(millis/1000);
              int minutes = (int)(seconds/60);
              int hours = (int)(minutes/60);
              minutes -= hours*60;
              seconds -= (hours*3600)+(minutes*60);
              return(((hours<10)?"0"+hours:""+hours)+":"+((minutes<10)?"0"+minutes:""+minutes)+":"+((seconds<10)?"0"+seconds:""+seconds));
         public void start() {
              startTime = -1;
              timer.setInitialDelay(0);
              timer.start();
         public long stop() {
              timer.stop();
              return(count);
         public static void main(String[] args) {
              JFrame frame = new JFrame("Countdown");
              CountUpLabel countUp = new CountUpLabel();
              frame.getContentPane().add(countUp, BorderLayout.CENTER);
              frame.setBounds(200,200,200,100);
              frame.setVisible(true);
              countUp.start();
    Denis

  • Exception at javax.swing.UIManager.setLookAndFeel(UIManager.java:435)

    Only in one machine (AIX 5.2 with J2RE 1.3.1 IBM) I got the following exception:
    "main" (TID:0x300C19D8, sys_thread_t:0x3003EF58, state:R, native ID:0x1) prio=5
         at java.security.AccessController.doPrivileged(Native Method)
         at sun.java2d.SunGraphicsEnvironment.<init>(SunGraphicsEnvironment.java:105)
         at sun.awt.X11GraphicsEnvironment.<init>(X11GraphicsEnvironment.java:82)
         at java.lang.Class.newInstance0(Native Method)
         at java.lang.Class.newInstance(Class.java:262)
         at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:72)
         at java.awt.Font.initializeFont(Font.java:285)
         at java.awt.Font.<init>(Font.java:319)
         at javax.swing.plaf.FontUIResource.<init>(FontUIResource.java:51)
         at javax.swing.plaf.basic.BasicLookAndFeel.getFont(BasicLookAndFeel.java:252)
         at javax.swing.plaf.basic.BasicLookAndFeel.initComponentDefaults(BasicLookAndFeel.java:271)
         at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:210)
         at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:80)
         at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1088)
         at javax.swing.UIManager.setLookAndFeel(UIManager.java:408)
         at javax.swing.UIManager.setLookAndFeel(UIManager.java:435)
    Other machine works fine.
    Any suggestion?
    Grazie

    So I can only assume that I have the the necessary resources installed correctly. Any thoughts on what might be causing my problem?
    com.sun.java.plat.windows.WindowsClassicLookAndFeel // the class you're trying to set
    com.sun.java.plaf.windows.WindowsClassicLookAndFeel // the class that is actually availableSee the difference?
    ~

  • How can I deploy multiple fonts with the ProfileManager

    I tried to add more than just one Font using the ProfileManager on Mac OS X Server 3.1.1
    There appears just one line to add one Font file. Do I need to combine all my fonts into one file to deploy it?
    Don't see a way to add more Font Payloads.

    I spoke to Apple's Enterprise support today about this problem, and the representative said that he is going to report this "issue" to Engineering. Not sure what this means, but I thought I would let you know.
    If you are trying to deploy multiple fonts to iOS devices, they suggested that I use Apple Configurator, which is available for free in the Mac App Store...

Maybe you are looking for

  • I  was billed four times for $8.98 and I do not  know why

    I logged on to iTunes 9/192013 and had to update my billing info. I updated Netflix and downloaded 2 free game apps. My iTunes account lists no charges. However, when I checked my bank statement online I saw that iTunes had billed me four times for $

  • Required report for the invoice processed twice for the same PO & Vendor

    Hi SAP MM experts, I want a  report which is to identify the same invoice processed twice against the same vendor and same PO which system cannot detect only  because the invoice numbers are manually entered slightly different, and that is why I also

  • Problems with awt.Toolkit on Tomcat

    Hello! I'm trying to get the Default Toolkit (java.awt.Toolkit.getDefaultToolkit() ) to determine the scrren size of the client, and Tomcat keeps throwing an Exception - now it's the website's Tomcat and the one on my localhost - there it worked.. Is

  • I just ran Etresoft and these are the results...Help?

    Problem description: iMac running sluggishly. EtreCheck version: 2.1.2 (105) Report generated December 11, 2014 at 4:02:28 PM EST Hardware Information: ℹ️   iMac (21.5-inch, Late 2009) (Verified)   iMac - model: iMac10,1   1 3.06 GHz Intel Core 2 Duo

  • Aperture library not showing in mail, iweb or iphoto

    After upgrading to 3.1 my Aperture Library is not coming up in other applications. It also is not showing up as an option for screen saver. Anyone have this issue?