[Solved] CLASSPATH for javax.swing libraries?

Hello,
I wanted to use the swing packages provided by java for developing cross platform GUIs. But, when I tried compiling it, I ended up with the following error:
HelloWorldSwing.java:1: package javax does not exist
import javax.swing;
After searching a bit online, I found out that the CLASSPATH variable needed to be set to use external java libraries. (I installed the jdk and jre packages). I tried setting CLASSPATH to /opt/java/jre/lib in my ~/.bashrc but that didn't help. What should I do to remedy this situation?
(This is the first time that I am trying to use external libraries like swing on Arch. So I am a Noob at this)
Thanks for your time!
Last edited by mgangav (2009-11-24 15:45:59)

urist wrote:
The
import javax.swing.event.*;
is unnecessary as it is covered by the previous import.
No, each package must be imported separately, even if one is "inside" the other.  I wrote a little test program to make sure   Try compiling it with line 4 commented/uncommented.
package foo;
import javax.swing.*;
//import javax.swing.event.*;
public class Thingy
public Thingy() {
JMenu menu = new JMenu("File");
menu.addMenuListener(new MenuListener() {
public void menuCanceled(MenuEvent e) {
System.out.println("canceled");
public void menuSelected(MenuEvent e) {
System.out.println("selected");
public void menuDeselected(MenuEvent e) {
System.out.println("deselected");

Similar Messages

  • WARNING: No saved state for javax.swing.JTable

    Hi All,
    I have a JTable component in my code and I used Netbeans to add swing components. However, I get this warning after I run my app:
    WARNING: No saved state for javax.swing.JTable[jTable1,0,0,329x80,alignmentX=0.0,alignmentY=0.0,border=,
            flags=251658568,maximumSize=,minimumSize=,preferredSize=,autoCreateColumnsFromModel=true,
            autoResizeMode=AUTO_RESIZE_SUBSEQUENT_COLUMNS,cellSelectionEnabled=false,editingColumn=-1,
            editingRow=-1,gridColor=javax.swing.plaf.ColorUIResource[r=128,g=128,b=128],
            preferredViewportSize=java.awt.Dimension[width=450,height=400],rowHeight=16,rowMargin=1,
            rowSelectionAllowed=true,selectionBackground=javax.swing.plaf.ColorUIResource[r=51,g=153,b=255],
            selectionForeground=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],showHorizontalLines=true,
            showVerticalLines=true]What is the reason of this? If I need to catch this exception, how can I add it with netbeans?
    Edited by: Darryl Burke -- broke a long line into several lines

    Set the name property of your JTable, it's a Netbeans thing, rather than a Java problem. table.setName("MyTable");Have a look at this thread for details: SessionStorage warning while program is running
    Please only post Java related questions here and post Netbeans questions to a netbeans forum/mailing list, thanks.

  • Missing Jar files javax.swing.text.Utilities(printTable)

    Hi Experts,
    please explain which jar files are required for Javax.swing.text.Utilites(printTable()).
    tilities utilities = new Utilities();
         ArrayList al = new ArrayList();
         al.add(IPrivateWOAccCodeView.IWOElement.RQT_NO);
         al.add(IPrivateWOAccCodeView.IWOElement.WO_TITLE);
         al.add(IPrivateWOAccCodeView.IWOElement.RQTR);
         al.add(IPrivateWOAccCodeView.IWOElement.TOT_AMT);
         al.add(IPrivateWOAccCodeView.IWOElement.STATUS);
         al.add(IPrivateWOAccCodeView.IWOElement.PLAN_START_DATE);
         al.add(IPrivateWOAccCodeView.IWOElement.TARGET_END_DATE);
         al.add(IPrivateWOAccCodeView.IWOElement.ACCOUNT_CODE);
         al.add(IPrivateWOAccCodeView.IWOElement.APPLY_AMOUNT);     
         //To print in HTML
         String printURL = (String) utilities.printTable(al,"Work Order Details By Account Code","Work Order Details By Account Code",wdContext.nodeWO()).get("url");
         wdContext.currentContextElement().setPrintURL(printURL);
        //@@end
    Error  in printTable that is method is undefined.
    Regards,
    Smruti
    Edited by: smruti moharana on Jun 20, 2011 8:10 AM

    According to my knowledge, there is no printTable method in javax.swing.text.Utilities class
    What are you trying to achieve?

  • Unable to set classpath javax/swing/japplet in Linux

    Hi,
    I have a problem in running an Applet program in Linux. If I run I get the following message.
    "Javax/swing/JApplet error Java.lang.NoClassDefFound Error".
    I have set my .bash_profile as follows:
    CLASSPATH=/usr/java/jdk1.3_0_01/jre/lib
    CLASSPATH=/usr/java/jdk1.3_0_01/lib
    CLASSPATH=/usr/java/jdk1.3_0_01/
    EXPORT
    Please tell me whether I have created the .bash_profile correctly. or anything to be changed. It will be great help if anybody hep in this regard. I am held up in my project.
    Thnaks.
    Mari
    11/09/02

    You don't need to set the CLASSPATH to get javax.swing.JApplet - the JVM "automagically" knows where the rt.jar file is. The only items you need in your CLASSPATH environment are third-party .jar files.
    I'm taking a wild guess based on your subject line, but I'll bet you mis-typed the ClassName - "JApplet," not "japplet." Your code should have
    import javax.swing.JApplet;in it.

  • Fix for PENDING in javax.swing.text.html.ParagraphView line #131

    Investigating source of HTMLEditorKit I found many PENDING things. That's fix for one of them - proper minimal necessary span detecting in table cells.
    Hope it will help to somebody else.
    import javax.swing.*;
    import javax.swing.text.html.*;
    import javax.swing.text.html.ParagraphView;
    import javax.swing.text.*;
    import java.awt.*;
    import java.text.*;
    import java.util.ArrayList;
    public class App extends JFrame {
        public static String htmlString="<html>\n" +
                "<body>\n" +
                "<p>The following table is used to illustrate the PENDING in javax.swing.text.html.ParagraphView line #131 fix.</p>\n" +
                "<table cellspacing=\"0\" border=\"1\" width=\"50%\" cellpadding=\"3\">\n" +
                "<tr>\n" +
                "<td>\n" +
                "<p>111111111111111111111111111111111<b>bold</b>22222222222222222222222222222</p>\n" +
                "</td>\n" +
                "<td>\n" +
                "<p>-</p>\n" +
                "</td>\n" +
                "</tr>\n" +
                "</table>\n" +
                "<p></p>\n" +
                "</body>\n" +
                "</html>";
        JEditorPane editor=new JEditorPane();
        JEditorPane editor2=new JEditorPane();
        public static void main(String[] args) {
            App app = new App();
            app.setVisible(true);
        public App() {
            super("HTML span fix example");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JSplitPane split=new JSplitPane(JSplitPane.VERTICAL_SPLIT, createFixedPanel(), createOriginalPanel());
            getContentPane().add(split);
            setSize(700, 500);
            split.setDividerLocation(240);
            setLocationRelativeTo(null);
        JComponent createOriginalPanel() {
            JPanel p=new JPanel(new BorderLayout());
            p.add(new JLabel("Original HTMLEditorKit"), BorderLayout.NORTH);
            HTMLEditorKit kit=new HTMLEditorKit();
            editor2.setEditorKit(kit);
            editor2.setContentType("text/html");
            editor2.setText(htmlString);
            p.add(new JScrollPane(editor2), BorderLayout.CENTER);
            return p;
        JComponent createFixedPanel() {
            JPanel p=new JPanel(new BorderLayout());
            p.add(new JLabel("Fixed HTMLEditorKit"), BorderLayout.NORTH);
            HTMLEditorKit kit=new MyHTMLEditorKit();
            editor.setEditorKit(kit);
            editor.setContentType("text/html");
            editor.setText(htmlString);
            p.add(new JScrollPane(editor), BorderLayout.CENTER);
            return p;
    class MyHTMLEditorKit extends HTMLEditorKit {
        ViewFactory defaultFactory=new MyHTMLFactory();
        public ViewFactory getViewFactory() {
            return defaultFactory;
    class MyHTMLFactory extends HTMLEditorKit.HTMLFactory {
        public View create(Element elem) {
            View v=super.create(elem);
            if (v instanceof ParagraphView) {
                v=new MyParagraphView(elem);
            return v;
    class MyParagraphView extends ParagraphView {
        public MyParagraphView(Element elem) {
            super(elem);
        protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
            r = super.calculateMinorAxisRequirements(axis, r);
            float min=getLongestWordSpan();
            r.minimum = Math.max(r.minimum, (int) min);
            return r;
        public float getLongestWordSpan() {
            if (getContainer()!=null && getContainer() instanceof JTextComponent) {
                try {
                    int offs=0;
                    JTextComponent c=(JTextComponent)getContainer();
                    Document doc=getDocument();
                    int start=getStartOffset();
                    int end=getEndOffset()-1; //don't need the last \n
                    String text=doc.getText(start, end - start);
                    if(text.length() > 1) {
                        BreakIterator words = BreakIterator.getWordInstance(c.getLocale());
                        words.setText(text);
                        ArrayList<Integer> wordBounds=new ArrayList<Integer>();
                        wordBounds.add(offs);
                        int count=1;
                        while (offs<text.length() && words.isBoundary(offs)) {
                            offs=words.next(count);
                            wordBounds.add(offs);
                        float max=0;
                        for (int i=1; i<wordBounds.size(); i++) {
                            int wStart=wordBounds.get(i-1)+start;
                            int wEnd=wordBounds.get(i)+start;
                            float span=getLayoutSpan(wStart,wEnd);
                            if (span>max) {
                                max=span;
                        return max;
                } catch (BadLocationException e) {
                    e.printStackTrace();
            return 0;
        public float getLayoutSpan(int startOffset, int endOffset) {
            float res=0;
            try {
                Rectangle r=new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);
                int startIndex= layoutPool.getViewIndex(startOffset,Position.Bias.Forward);
                int endIndex= layoutPool.getViewIndex(endOffset,Position.Bias.Forward);
                View startView=layoutPool.getView(startIndex);
                View endView=layoutPool.getView(endIndex);
                int x1=startView.modelToView(startOffset,r,Position.Bias.Forward).getBounds().x;
                int x2=endView.modelToView(endOffset,r,Position.Bias.Forward).getBounds().x;
                res=startView.getPreferredSpan(View.X_AXIS)-x1;
                for (int i=startIndex+1; i<endIndex; i++) {
                    res+=layoutPool.getView(i).getPreferredSpan(View.X_AXIS);
                res+=x2;
            } catch (BadLocationException e) {
                e.printStackTrace();
            return res;
    }Regards,
    Stas

    I'm changing the foreground color with
    MutableAttributeSet attr = new SimpleAttributeSet();
    StyleConstants.setForeground(attr, newColor);
    int start=MyJTextPane..getSelectionStart();
    int end=MyJTextPane.getSelectionEnd();
    if (start != end) {
    htmlDoc.setCharacterAttributes(start, end, attr, false);
    else {
    MutableAttributeSet inputAttributes =htmlEditorKit.getInputAttributes();
    inputAttributes.addAttributes(attr);   

  • Javax class libraries in VJ++ 6.0

    Hello,
    I'm using VJ++ 6.0: it does not recognise the javax class libraries, among others. I've installed version 1.4.2_04 of the SDK, which contains all the new class libraries. There is a directory containing the old class libraries, c:\winnt\java\packages. But each time I open VJ++, it goes to these old class libraries. So a project that uses javax won't compile. However: if I compile from the command prompt, it works fine. I want to use VJ++ though, as it's easier to use for writing code. Is there any way I can update VJ++ to take from the new class libraries? There's an option in Project/prjExample Properties, in the ClassPath tab, which allows me to extend the project ClassPath. This only seems to take zip files though - and all of the 1.4.2 is contained in jar files. Could there be somewhere else where this can be done?
    Please help!

    no, you cant simply combine different classpaths/jvs/compilers.
    J++ uses an Microsoft-Compiler and a Microsoft-JVM so theres no chance at all to get this working. (However there is an external swing-package for 1.1-class jvms but it is outdated and not recommended at all).
    Have you ever tried JBuilderX or other modern IDEs. Most are free for non-commercial use and are much more standard-compliant and comfortable that J++.
    J++ isnt even support by microsoft since a long time, so switch so something new you are sitting on a dead end!
    lg Clemens

  • Path in Classpath for file SapMetamodelWebdynproContent.zip not found.

    How to get rid of these warnings?
                   [Warning]: Path in Classpath for file SapMetamodelWebdynproContent.zip not found.          
    Warning               [Warning]: Version for file SapMetamodelWebdynproContent.zip not found.          
    Warning               [Warning]: Versions of 'SapDictionaryTypeServices.jar' have different prefix.          
    Warning               [Warning]: Versions of 'SapDictionaryTypesRuntime.jar' have different prefix.     
    thanks in advance.

    Hi,
    This is a common problem when you import projects to NWDS. Do like this.
    1.Change to Navigator tab in NWDS and delete gen_wdp folder.
    2.Switch to Web Dynpro Explorer. Select the Project -> Right click-> Select properties -> in the wizard select Java Build Path -> Select Libraries tab -> You will find jar files with warnings
    3.Remove the jar and add the jar file with same name to the project one by one.
    4.For each jar file repeat step 3.
    5.Save the project
    Or
    removed the read-only property from all folders / files of the project and it solved my problem.
    Hope this helps!!
    Thanks & Regards
    Vijay K

  • Import javax.swing problems

    hey
    I am new to java and have recently downloaded j2sdk1.4.2_04. I am trying to create a simple graphical application. However, It doesnt seem to import the javax.swing.* libraries. I understand that there is the src.zip in the directory, so I unzipped it but it still doesn't read the package. I read elsewhere on this forum that you should set the path to src.zip. I have tried that and it also doesnt work. My current path is:
    PATH=C:\j2sdk1.4.2_04\lib\src.zip;C:\j2sdk1.4.2_04\bin
    Is there an error in this, or what else should I try? All suggestions greatly appreciated.

    There's no need to set your classpath when importing any of the standard packages that are provided by the JDK. Perhaps you could post a (small) code sample and the compiler error you are getting.

  • Package javax.swing not found in import!

    I recently installed JDK 1.3.1_02 on WinNT4.0 and I cannot compile javax
    packages without getting the following error:
    Package javax.swing not found in import
    I've tried every combination of modifying the CLASSPATH system variable
    I can think of. I have no problem compiling java packages but not
    javax packages. I followed the installation instructions to the letter.
    What am I missing? Surely someone is running the same version of
    the JDK I am on WinNT 4.0.

    Thanks again!!! I had an older version of javac running on my system any time I ran
    outside of the bin where the latest javac was installed. I removed the older version
    of the jdk and now I can compile from any directory. I really appreciate the help,
    I was wracking my brain.
    By the way, -version is not a valid flag for javac.exe, although it is for java.exe.
    signed,
    grateful in cyberspace

  • Missing classes from the javax.swing package?

    Can anyone throw any light on what appears to be a missing class from the javax.swing package?
    When CelsiusConverter.java from The Swing Tutorial (code fragment shown below) is compiled the JFrame class can't be found.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CelsiusConverter implements ActionListener {
        JFrame converterFrame;Despite the package javax.swing being imported, the compiler does not seem to be be able to find the JFrame class.
    CelsiusConverter.java:14: Class JFrame not found in type declaration.
        JFrame converterFrame;To attempt to solve this issue all the files in jdk1.5.0_02\lib were added to CLASSPATH.
    CLASSPATH was set to C:\Program Files\Java\jdk1.5.0_02\lib\dt.jar;C:\Program Files\Java\jdk1.5.0_02\lib\htmlconverter.jar;C:\Program Files\Java\jdk1.5.0_02\lib\jconsole.jar;C:\Program Files\Java\jdk1.5.0_02\lib\tools.jar;C:\Program Files\Java\jdk1.5.0_02\lib;C:\Program Files\Java\jdk1.5.0_02\lib\ir.idl;C:\Program Files\Java\jdk1.5.0_02\lib\jawt.lib;C:\Program Files\Java\jdk1.5.0_02\lib\jvm.lib;C:\Program Files\Java\jdk1.5.0_02\lib\orb.idl;C:\Program Files\Java\jdk1.5.0_02\demo\jfc\SwingApplet\SwingApplet.jar;.;c:\CoreJavaBook

    This is extremely strange... If you're sure it's not a problem in your code or with your classpath, the only other thing I can think to suggest is re-downloading / installing java

  • Classpath for J2SDK 1.4.1

    Hello,
    I'm a beginner to Java and I'm using Mandrake Linux 9.0 and J2SDK 1.4.1. I would like to ask how to set the class path for the SDK? Meanwhile, I always get this error message when compilering a java file that uses class packages.(i.e. javax.swing.JOptionPane)
    Some of the error:
    ===
    $ javac DemoPaint.java
    DemoPaint.java:4: error:Cannot find class "JApplet" [JLS 8]
    $
    ===
    $ javac Lab4_1.java
    Lab4_1.java:1: error:Import of type "javax/swing/JOptionPane" from unamed package [JLS 7.6]
    Lab4_1.java:1: error:Cannot find class "javax/swing/JOptionPane" [JLS 8]
    $
    ===
    Thank you!
    Charles Cheng

    If did you set correct CLASSPATH?
    CLASSPATH="$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/too
    s.jar:."Don't do that. In general, never put JDK jars into
    your classpath. Let the Java VM find it by itself -
    they all do.
    Make sure that Mandrake is not shipping with Kaffe or
    any such silly VM (RedHat used to do this -
    /usr/bin/java was Kaffe!).
    Check your $PATH, and make sure that
    /usr/java/j2sdk1.4.1_01/bin is in your PATH before
    /usr/bin, and that that is the Java that is picked
    up:
    $ java -version
    java version "1.4.1_01"
    Java(TM) 2 Runtime Environment, Standard Edition
    (build 1.4.1_01-b01)
    Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed
    mode)If you see this output, you should be OK.
    Once again, do NOT put any standard Java jars into
    your CLASSPATH!.A PROBLEM
    After I removed JDK jars from CLASSPATH, my jikes cannot work. It tell me cannot find java.util.........

  • Changing javax.swing class

    Hello,
         I am an experienced programmer new to java. I found a solution to a problem I am having with BoxLayout in the bug database. The solution makes a change to the SizeRequirements class in javax.swing. I found the source for the class and have recompiled it. But the recompiled class is not being picked up. What do I do next? The classes all seem to be in a jar file although I can't find one with SizeRequirements. Is there the concept of linking in Java or do I just need to put the class in the right path location?
    Thanks,
    Lori

    ...file although I can't find one with SizeRequirements. If you can't find it then you might want to go back to the drawing board since you probably have a different java version.
    I don't believe standard class files are loaded via the classpath.
    This command line option is taken from the javadocs
    -Xbootclasspath/p:path
    Specify a semicolon-separated path of directires, JAR archives, and ZIP archives to prepend in front of the default bootstrap class path. Note: Applications that use this option for the purpose of overriding a class in rt.jar should not be deployed as doing so would contravene the Java 2 Runtime Environment binary code license.
    The last sentence is important.

  • 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.GroupLayout - problem

    Hi
    Puzzling problem has occurred when developing the same application on different PC�s and using the same IDE (Netbeans 5.5) on both.
    The problem is that the �javax.swing.GroupLayout� class is being used when inserting netbeans GUI components on one of the PC�s. However, the other PC uses �org.jdesktop.layout.GroupLayout� and generates an error when trying to compile the �javax.swing.GroupLayout� components. It cannot find the javax.swing.GroupLayout� class.
    The jdk is jdk 6 for both.
    Can anyone shed any light on this?
    Regards
    GB

    Did you check the project properties?
    Project properties | Categories: Libraries --> Java Platform: JDK 1.6
    (javax.swing.GroupLayout works only with 1.6)

  • NoClassFoundException javax.swing.JList

    Hi
    I have done a quite a lot of java applications but not applets.
    No trying to cover this I get problems with CLASSPATH I think.
    When running my test applet with just one task in init() add a Jlist I get the NoClassFoundException javax.swing.JList what am I doing wrong how does this work ?

    You should use this code for your Applet: (insteed of <applet ...>)
    <OBJECT codetype="application/java" NAME="theName"
    WIDTH = 450 HEIGHT = 250 classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
    <PARAM NAME = NAME VALUE = "theName" >
    <PARAM NAME = CODE VALUE = "theName.class" >
    <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3.0">
    <PARAM NAME = MAYSCRIPT VALUE = true >
    <PARAM NAME="scriptable" VALUE="true">
    <EMBED NAME="theName" MAYSCRIPT=true scriptable=true type="application/x-java-applet;version=1.2" java_CODE = "theName.class" WIDTH = 350 HEIGHT = 250 pluginspage="http://java.sun.com/products/plugin/1.2/plugin-install.html"></EMBED>
    </OBJECT>
    This will use JRE1.3. If this is not installed on the client maschine jre is installed automaticly.
    MayScript and Scriptable are used to connect the Apllet via JavaScript.
    I hope this could help.
    J&ouml;rn

Maybe you are looking for

  • Streaming in iOS6 disables wifi

    Since iOS 6 "upgrade," my iPad (3rd gen) acknowledges and connects to wifi. I can surf the web, but if I try to stream anything, YouTube, Netflix, etc... It works for anywhere between thirty seconds and two minutes, but then the wifi shuts off.  I ha

  • 4.0 EA2 Commit in subversion gives error due to missing parent entry

    Hello, I am using Data Modeler 4.0 EA2 with SVN. In the following scenario an error occurs when committing the change in SVN: 1- open a model in DM 2- add a physical model to the relational model 3- save the model 4- commit the changes in SVN The fol

  • Why does my iTunes only show iTunes U and podcast options

    Why does my iTunes only show iTunes U and podcast options at the bottom. I just want to be able to watch movies on my iPad :( Plus when I go to the videos app and tap go to iTunes Store I get a blue message that says "cannot connect to iTunes Store".

  • Multiple Records in XI

    Hi Folks , Can you guide me in 1. Handling multiple records from source and posting one at a time into JDBC . 2. Fetching single records from JDBC and sending as a batch. Regards,

  • I need a new Top and Bottom Shell (Underside and Top of the main part of the laptop)

    I can't find the parts I need in partsurfer, though I may have messed up. Any help would be appreciated. On a related note, HP Really needs to improve their issues with the left heinge.