Java 5 generic does not work

In coding with java 5, I found I could not use Java 5 generic for all cases. For example, JAAS define a LoginModule interface as following
boolean abort()
boolean commit()
void initialize(Subject subject, CallbackHandler callbackHandler, Map<String,?> sharedState, Map<String,?> options)
Initialize this LoginModule.
boolean login()
boolean logout()
In initialize method, the login module should hold the reference to sharedState parameter and in its login method, the module put values into sharedState object to allow other login modules to share states. For example, If I would like to share password with other module, I should be able to do the following
sharedState.put("javax.security.auth.login.password", password);
But the java 5 compiler, says I can't put value into the sharedState map since ? is a wildtype.
Any one can tell me how to put values into the map Map<String, ?>.
Or If java has some good solution for this.
thanks in advance.
hao

minghao wrote:
I agree with you. If the semantics of java generic ? is not reworked, then the login module interface definition is not right.More precisely: if neither the semantics of ? nor the LoginModule interface is changed then the LoginModule interface doesn't make a lot of sense as it is.
But I think the semantics of java generic ? should be reworked.Why? Simply because a single interface is ill-designed?
If we changed the semantics of Map<String, ?> to allow .put() to be called, then a lot of code that depends on that semantics would break.
And if you want a Map from String to any object type, then simply use a Map<String, Object>. That's what it's there for.
It should loose some restrictiions if there's some type explicitly defined, such as Map<String, ?> if Key's type is explicitly defined, then the value could be added by using wildcard.I don't really get what you want. But I think you need to get a deeper understanding of generics. The two parameters of the Map interface (K and V, if I remember correctly) are completely unrelated.
You could give the same example with Collection<?>: It doesn't make any guarantees about the type it returns (i.e. it returns plain Objects) and doesn't accept any calls to add() because you can't possibly fullfil the type-requirements of the wildcard type.
Those are perfectly acceptable, fine and useful semantics. I see no need to change that.

Similar Messages

  • Java.util.ProperyPermission does not work for

    Hi again!
    I have some problems with a security.policy file. Its content is provided below:
    grant{
         //Alow the client to connect to any port above 1024
         permission java.net.SocketPermission "*:1024-", "connect";
    permission java.util.PropertyPermission "user.language", "read, write";
    Unfortunately, the java.util.PropertyPermission does not work. I always get the following exception:
    java.security.AccessControlException: access denied (java.util.PropertyPermission user.language write)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
    at java.security.AccessController.checkPermission(AccessController.java:427)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at java.util.Locale.setDefault(Locale.java:352)
    at essex.kkarad.cache.daemon.SimplePopulationStrategy.doPopulate(SimplePopulationStrategy.java:41)
    at essex.kkarad.cache.daemon.Populator.run(Populator.java:42)
    Is there any problem with the decleration of the premission? Any ideas?

    Err, this may come as a shock, but it's because you changed the system clock.
    The Timer class works out the absolute time when to next to do something, and when you change the system clock you break that time.
    How much are you changing it by?

  • HT5559 Java web start does not work

    I have followed the instructions in this article, including the last step about web start, but it still does not work, neither applets or web start. When I try to launch a JWS application by double clicking it I get the dreaded warning dialog:
    To open this Web Start application, you need to download the Java Runtime Environment.
    Click “More Info…” to visit the website for the Java Runtime Environment.
    I do have a JRE installed, 1.6, since I for compatibility reasons can't upgrade.
    Trying to launch a web start application from the commandline looks like this:
    $ javaws /tmp/airview.jnlp
    Java Web Start splash screen process exiting ...
    Can not find message file: No such file or directory
    Regular Java-programs work fine.
    $ java -version
    java version "1.6.0_37"
    Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
    Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)

    Read this thread https://discussions.apple.com/thread/4789691?tstart=0
    This fixed the issue for me:
    sudo /usr/libexec/PlistBuddy -c "Delete :JavaWebComponentVersionMinimum" /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/XProtect.meta. plist
    In the comments to the linked article someone suggests to comment out the node in stead of deleting it. Probably safer (it's explained further down how to do that). Anyway I already spent to much time on this nonsense, deleted it and it worked, so I'm happy.

  • HT5682 April 22, just installed the latest update to fix the Java problem, it does not work.

    About a week ago I installed a MAC update. I discovered that I was unable to play POGO games. I know that is not up there with all other uses of MAC... let's get back on track here. I have uninstalled and reinstalled, and reset preferences at least 6 times to get JAVA back.
    Some of my new BFF sites:
    Java for OS X 2013-002: How to re-enable the Apple-provided Java SE 6 web plug-in and Web Start functionality.
    Why is Java not working on my Mac?|EA Help
    Re: Bridge - Page 2 - Answer HQ   Java POGO
    Java for OS X 2013-003    get applet from Oracle
    My Intel MAC  circa 2009, is  running MAC OS X Lion  10.7.5   Safari 6.0.4
    Today I received another update from Apple stating it would provide the answer to POGO 6 and you can select certain sites that can be accessed.  
    This also was a FAIL!
    I now know the steps, can access TERMINAL without shaking, have learned to use GO to access UTILITIES.  I still end up with JAVA not recognizing that their software has a place in my heart and I truly hope on my computer soon.
    I have been playing a horrible game of Solitaire on another site.
    Are there others out there with this problem or is it just me? Can anyone suggest anything else?

    Thank you BDAua. This is what I typed and the reply from Terminal
    java -version
    java version "1.6.0_45"
    Java(TM) SE Runtime Environment (build 1.6.0_45-b06-451-11M4406)
    Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01-451, mixed mode)
    BTW - this application does NOT show up in the Applications folder and I consider that a bit odd.
    I also  tried typing Java for my computer to search for and this is what I got under
    Overview:
    PID: 944
    Host: localhost
    Main class: <unknown>
    Arguments: <none>
    JVM: Java HotSpot(TM) 64-Bit Server VM (20.45-b01-451, mixed mode)
    Java: version 1.6.0_45, vendor Apple Inc.
    Java Home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    JVM Flags: <none>
    Heap dump on OOME: enabled
    I hope something is helpful within all of this info!

  • Java plug-in does not work on DELL laptop w/ ATI video card

    Hello there,
    I try to run Java Web Start on my new DELL laptop with ATI mobility radeon 7500 video card. When I run the SwingSet2 App, the whole system locks up, so I have to do a hard re-boot on my laptop. I found that this problem happens to other DELL laptops when I address this issue to my co-workers. Nevertheless, this problem is fixed when I run Java Web Start on some other desktops that does not use the ATI video card.
    Have any of your experience this? Does any know any workaround for this problem?
    Please help. Thanks.
    A.A.

    Hello there,
    I try to run Java Web Start on my new DELL laptop with
    ATI mobility radeon 7500 video card. When I run the
    SwingSet2 App, the whole system locks up, so I have to
    do a hard re-boot on my laptop. I found that this
    problem happens to other DELL laptops when I address
    this issue to my co-workers. Nevertheless, this
    problem is fixed when I run Java Web Start on some
    other desktops that does not use the ATI video card.
    Have any of your experience this? Does any know any
    workaround for this problem?
    Please help. Thanks.
    A.A.Do you use sun one studio? Do you experience system hangs and blue screens?
    I do, and I was kind of hoping I'm not alone.
    Morten

  • Java 3D: vrml97 does not work

    Hi,
    I tried to run a Java3D application (it requires VRML Java3D loader) from the following url:
    http://www.gris.uni-tuebingen.de/projects/schickard/WSApplet.html
    But it didn't work... then I tried to run it offline (via console: java -cp WSApplet.zip WSApplet & appletviewer WSApplet.html).
    And the same result:
    The browser message sad that the initialization is ok (�WSApplet: initiated�) but then the task is aborted with the following error message:
    vrml.node.Node.<init>(Lcom/sun/j3d/loaders/vrml97/impl/Node;)V
    But I couldn't deal with this message.
    So I asked one of the developer (Frank Hanisch) of this Applet if can send me a proper solution for this problem. He sent me another version of vrml97.jar
    Java3D is correctly installed and also the OpenGL implementation.
    But the problem still occurs. So what can I do????
    Some system information:
    AMD AthlonXP with WinXP SP2;
    Path=C:\PROGRA~1\Java\JDK15~1.0_0\bin;C:\PROGRA~1\Java\JDK15~1.0_0\jre\bin (just an extract)
    JAVA-Console-Log:
    Initialising applet and loading data, this will take some time ...
    file:/C:/Programme/Java/tutorOffline/j3d/samples/WSApplet/WSApplet.htmltextures/helpcursor.gif
    file:/C:/Programme/Java/tutorOffline/j3d/samples/WSApplet/WSApplet.htmltextures/helpcursor2.gif
    file:/C:/Programme/Java/tutorOffline/j3d/samples/WSApplet/WSApplet.htmltextures/rotcursor.gif
    file:/C:/Programme/Java/tutorOffline/j3d/samples/WSApplet/textures/wsgold.gif
    file:/C:/Programme/Java/tutorOffline/j3d/samples/WSApplet/textures/wswood1.jpg
    file:/C:/Programme/Java/tutorOffline/j3d/samples/WSApplet/textures/wswood2.jpg
    java.lang.NoSuchMethodError: vrml.node.Node.<init>(Lcom/sun/j3d/loaders/vrml97/impl/Node;)V
         at com.sun.j3d.loaders.vrml97.impl.Node.wrap(Node.java:114)
         at com.sun.j3d.loaders.vrml97.VrmlScene.<init>(VrmlScene.java:67)
         at com.sun.j3d.loaders.vrml97.VrmlLoader.doLoad(VrmlLoader.java:119)
         at com.sun.j3d.loaders.vrml97.VrmlLoader.load(VrmlLoader.java:106)
         at Schickard.createScene(Schickard.java:193)
         at WSApplet.start(WSApplet.java:89)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)

    Ok, I'll be clearer. Oracle says you're giving it the wrong username and password. Therefore you are.
    If the first of your programs is working, and the second isn't, then...
    The second program is submitting the wrong username, or
    The second program is submitting the wrong password, or
    The second program is in fact connecting to a different database, or
    Some combination of these.
    It's as simple as that. Sorry. Now you have to figure out whether you're typing it in differently, or it's getting changed elsewhere in your code. But it will be in your code. Yes, it could be the environment, I suppose, but since you're not getting a problem connecting to the database at all, only with the authentication details you're providing, I think this is very unlikely to be the explanation - assume it is NOT an environmental problem and you'll probably find it's something annoyingly simple.

  • I have java. It does not work w/firefox. Need to enable BUT it does not show up in firefox under tools-option-content. I need to "enable" but can't when does not appear. How get java to play with firefox?

    Firefox version 3.6.12
    Java - I believe 6 update 22 something like that - have verified have most up-to-date available.
    I am running on windows xp with upgrade 2. (I can not upgrade to 3 without crashing my system. Not even with hp's "fix" unless they've licked that calf over again.)
    Restarting computer has not solved either.

    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"

  • Set CLASSPATH does not work, how do I run java.exe?

    Hi guys,
    I have a problem running the java.exe and I'm using Win XP. Here is my problem:
    Under the command prompt, I set the path: path = C:\Program Files\Java 2\j2sdk1.4.2_05\bin
    Then I created a folder in E:\Hello. I save my Hello.java in that folder, and I compiled it:
    javac Hello.java
    Now, there is a Hello.class created in that folder.
    Then I try to run it: java Hello
    but I got an error: "Exception in thread "main" java.lang.NoClassDefFoundError: Hello"
    So, I try to set CLASSPATH, however, the problem remains, no matter how hard I try.
    Any ideas?

    None of the suggestion worked, I wonder why???
    Here is my location for the JDK:
    C:\Program Files\Java 2\j2sdk1.4.2_05\bin
    Here is my location for my Java project file:
    E:\JavaProject\Hello
    Here is the file name:
    Hello.java
    Here is the command prompt:
    C:\Documents and Settings\Alex Ngai> e:
    E:\> cd JavaProject
    E:\JavaProject> cd Hello
    E:\JavaProject\Hello> path = C:\Program Files\Java
    2\j2sdk1.4.2_05\bin
    E:\JavaProject\Hello> javac Hello.java
    E:\JavaProject\Hello> java Hello
    Exception in thread "main"
    java.lang.NoClassDefFoundError: Hello
    E:\JavaProject\Hello> java -cp Hello
    // Does not work, it lists all of the options for java
    E:\JavaProject\Hello> set CLASSPATH =
    E:\JavaProject\Hello
    CLASSPATH="C:\Program
    Files\Java\j2re1.4.2_04\lib\ext\QTJava.zip"
    E:\JavaProject\Hello> java Hello
    Exception in thread "main"
    java.lang.NoClassDefFoundError: Hello
    // I have tried a lot more, none of them won't work!!
    Now what should I try in the following command prompt?
    E:\JavaProject\Hello>Given the above there is only one possible explaination.
    You have a file named "Hello.java".
    In that file you have a non-public class which is NOT named "Hello". Instead it is named something like "HelloWorld" or even "hello" (case matters.)

  • Java does not work at all upon using the update manager to update to firefox 3.6.10 for Ubuntu 9.0.4

    OS: Ubuntu 9.0.4
    Browser: Firefox 3.6.10
    upon updating to firefox 3.6.10, java does not work at all.
    websites that use java do not work at all anymore, when they worked just fine before the updating thru update manager. e.g. hulu website cannot play any of the shows.
    i can give the folder of bookmarked pages i tried.
    how to do that on here, i've yet to see if possible.
    i can even give saved text from the terminal concerning certain attempts.
    when i updated thru update manager, it gave some weird java plugin that wasn't there before "The IcedTea Web Browser Plugin IcedTea6 Java Web Browser Plugin (execution of applets on webpages)".
    i uninstalled this as instructed by an answer found in one of the pages i saved, cuz it was conflicting w/another java program the updater said i needed. right now, i don't remember for sure what it was. it perhaps was realplayer flash or Java itself. w/all the hours/days of searching i put in, it's difficult if not downright impossible for me to remember all the specifics of what i tried.
    i've searched throughout many webpages (including many searches on mozilla, ubuntu, java, etc) for instruction in fixing the problem.
    oh, and incidentally, on the Java site, when i try the verify test of Java, firefox pops up with that yellow bar right below the slew of tabbed website windows, giving the statement "additional plugins are required to display all the media on this page. (w/link to) install missing plugins ." which is what i do, go thru the requesting plugin installation. it comes up with, guess what, the IcedTea Java Plugin. i click on the 'next' in the "Plugin Finder Service" box that pops up, & all it gives me is "No plugins were installed. IcedTea ...Plugin failed. and the link 'find out more about plugins or manually find missing plugins'". the link takes me to some of the very things/plugins that wouldn't install in the first place. the Java test failure is a LOL funny, as what plugin it is saying is required (IcedTea) is a recommended alternate program to display the very test in the first place.
    i followed the given instructions on those many searched pages, in every case (barring what i may have just plain missed), but to no avail.
    i've even gone to the point of trying to reinstall the previous 3.5.13 firefox version, from mozilla site. even that wouldn't install.
    i've tried installing Java for my sys direct from it's site. nada.
    now it's time for me to post the problem & perhaps someone will come up with some kind of "dummy" way to fix it.
    until then many sites a regularly use are totally useless to me on this fast puter.
    the only way i can get to use such sites, are two choices: 1. use a dinosaur laptop, which is slower than molasses & cannot handle to any streaming stuff, or 2. use an available internet access puter at the library. but useage for ea person per day is limited to only one hour a day. and one can end up waiting for an hour or more ( in the busiest periods) to even get to use one.
    so, is there anyone at all, who knows any for-sure working fix for this problem?
    thanks muchly :^D
    p.s. i can't pay anybody any money for such help, as is required in certain sites (e.g. Java website), cuz i don't have any.
    i can pay in labor tho, if there is someway to find someone who can physically be at this puter w/me, taking me step-by-step
    sorry for the 20-pg essay. i hope it was all clearly understood. if, not, well, clear communication is always what is needed, ask away.

    Your above posted system details show outdated plugin(s) with known security and stability risks.
    *Shockwave Flash 9.0 r999
    Update the [[Managing the Flash plugin|Flash]] plugin to the latest version.
    *http://www.adobe.com/software/flash/about/
    In Firefox 3.6 and later versions you need the Next-Generation Java™ Plug-In present in Java 6 U10 and later (Linux: libnpjp2.so; Windows: npjp2.dll).
    http://java.com/en/download/faq/firefox_newplugin.xml
    See also http://java.sun.com/javase/6/webnotes/install/jre/manual-plugin-install-linux.html

  • Hi, I have a MAC (version 10.10.2) and installed Creative Suite one year ago. Now I want to open the Illustrator, but it does not work. It says I should install old Java SE 6-Runtime-Version to open „Adobe Illustrator CS6". Where can I find it? Thanks for

    Hi, I have a MAC (version 10.10.2) and installed Creative Suite one year ago. Now I want to open the Illustrator, but it does not work. It says I should install old Java SE 6-Runtime-Version to open „Adobe Illustrator CS6“. Where can I find it? Thanks for your answer! Jana

    Prompted to install Java SE 6 Runtime | Mac OS 10.9
    Mylenium

  • Excel File read using WebUtil does not work. Gives java.lang.NoSuchMethodEr

    We have a form which reads from an Excel File. The form works in development env., but in the live env when we deployed the form it does not work. Form fails @ the 1st call to Client_OLE2 where we set the Excel file to read.
    For both the envs. the values are given here:
    (1.) Client Forms Version : Forms [32 Bit] Version 10.1.2.0.2 (Production)
    (2.) Application Server Version : 10.1.2.0.2
    (3.) AS Linux Version : (Live) RHEL 5.7 Tikanga / (Dev) Red Hat Enterprise Linux AS release 4 (Nahant Update 4)
    (4.) Client Sun JRE Version :Version 1.5.0 (build 1.5.0_10)
    (5.) Client Web Browser & Version: I.E 8.0.6001 or Mozilla  3.0.15
    (6.) WebUtil Version: 1.0.6Both envs. are the same except the Linux version.
    Works fine in Dev but does not work in Live. Other Webutil functions like file open dialog box works fine in live, only this Excel read is not working.
    Full Error message
    Java Plug-in 1.5.0_10
    Using JRE version 1.5.0_10 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\dinesha.IIL
    c:   clear console window
    f:   finalize objects on finalization queue
    g:   garbage collect
    h:   display this help message
    l:   dump classloader list
    m:   print memory usage
    o:   trigger logging
    p:   reload proxy configuration
    q:   hide console
    r:   reload policy configuration
    s:   dump system and deployment properties
    t:   dump thread list
    v:   dump thread stack
    x:   clear classloader cache
    0-5: set trace level to <n>
    RegisterWebUtil - Loading WebUtil Version 1.0.6
    proxyHost=null
    proxyPort=0
    connectMode=HTTP, native.
    Forms Applet version is : 10.1.2.0
    Exception in thread "AWT-EventQueue-3" java.lang.NoSuchMethodError:
    com.jacob.com.Dispatch.put(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V
         at
    oracle.forms.webutil.ole.OleFunctions.set_obj_property(OleFunctions.java:1216)
         at
    oracle.forms.webutil.ole.OleFunctions.setProperty(OleFunctions.java:333)
         at oracle.forms.handler.ComponentItem.setCustomProperty(Unknown Source)
         at oracle.forms.handler.ComponentItem.onUpdate(Unknown Source)
         at oracle.forms.handler.JavaContainer.onUpdate(Unknown Source)
         at oracle.forms.handler.UICommon.onUpdate(Unknown Source)
         at oracle.forms.engine.Runform.onUpdateHandler(Unknown Source)
         at oracle.forms.engine.Runform.processMessage(Unknown Source)
         at oracle.forms.engine.Runform.processSet(Unknown Source)
         at oracle.forms.engine.Runform.onMessageReal(Unknown Source)
         at oracle.forms.engine.Runform.onMessage(Unknown Source)
         at oracle.forms.engine.Runform.processEventEnd(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)
         at oracle.ewt.lwAWT.LWComponent.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.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)We connected to Live AS server via VPN and ran the Form in a client machine (where the Dev. is working) but same problem.
    Any help would be greatly appreciated.

    Channa,
    I sounds like you might have missed a configuration step on your Linux application server (AS). I recommend you go back through the configuration of your AS and verify each step of the WebUtil Runtime Setup Checklist was completed correctly. Seach the Forms Help system on "Runtime Setup Checklist" for a copy of the checklist.
    Hope this helps,
    Craig B-)
    If someone's response is helpful or correct, please mark it accordingly.

  • Java bean, works in Integration Engine but does not work in Adapter Engine.

    In connection to the following thread:
    PayloadZipBean - variable filename inside the archive
    I am trying to use the same bean.
    However I can see, that the bean is working correctly when I use Integration Engine.
    But if I am using ICo (AAE) and using the same bean in the receiver, I can see, that the bean gets called but does not work correctly.
    The audit log added to my bean shows, that the bean could read the filename correctly from the Dyanic Config in the message, but it cannot write the same into the message.
    Could you please help on this?

    Your above posted system details show multiple Java Console extensions.
    You can uninstall (remove) the Java Console extensions and disable the Java Quick Starter extension, you do not need them to run Java applets.
    See http://kb.mozillazine.org/Java#Multiple_Java_Console_extensions
    See also http://www.java.com/en/download/help/quickstarter.xml - What is Java Quick Starter (JQS)? What is the benefit of running JQS? - 6.0
    Disable the Java Quick Starter extension: Tools -> Addons -> Extensions
    Control Panel -> Java -> Advanced tab -> Miscellaneous -> Java Quick Starter (disable)
    You can try a direct connection: <br />
    Control Panel > Java > General tab > "Network Settings...": "Direct Connection" (enable)

  • JTable - isEditing does not work in Java 1.4

    I just upgraded jdk1.1.8 with swing 1.1.1 to Java1.4. The isEditing method doesn't work on Java1.4. When I edit a cell in the JTable and click a button , the value of the last edited cell is lost. I was able to catch the edited value by calling isEditing in jdk1.1.8 but Java 1.4 does not detect that the cell was edited. Is this a bug? Has anyone experience this problem? Is there a work around solution? Please help!!!

    Hi,
    Below is the code that I modified from a sample code in Java Tutorial. I added an OK button. The isEditing method does not trap the edit the first time but does on the second edit in JDK1.4. However, it works in JDK1.1.8. Am I doing something wrong or is this a bug? I desperately have to solve this problem to upgrade to JDK1.4. Thank-you for your help! I really appreciate it!
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.JScrollPane;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    import javax.swing.JOptionPane;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.event.*;
    import javax.swing.table.*;
    public class TableDemo extends JFrame {
    private boolean DEBUG = true;
    private JPanel buttonPanel;
    private JTable table;
    public TableDemo() {
    super("TableDemo");
    MyTableModel myModel = new MyTableModel();
    table = new JTable(myModel);
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane to this window.
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    // create OK, Reset, and Cancel buttons
    createButtons();
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    class MyTableModel extends AbstractTableModel {
    final String[] columnNames = {"First Name",
    "Last Name",
    "Sport",
    "# of Years",
    "Vegetarian"};
    final Object[][] data = {
    {"Mary", "Campione",
    "Snowboarding", new Integer(5), new Boolean(false)},
    {"Alison", "Huml",
    "Rowing", new Integer(3), new Boolean(true)},
    {"Kathy", "Walrath",
    "Chasing toddlers", new Integer(2), new Boolean(false)},
    {"Mark", "Andrews",
    "Speed reading", new Integer(20), new Boolean(true)},
    {"Angela", "Lih",
    "Teaching high school", new Integer(4), new Boolean(false)}
    public int getColumnCount() {
    return columnNames.length;
    public int getRowCount() {
    return data.length;
    public String getColumnName(int col) {
    return columnNames[col];
    public Object getValueAt(int row, int col) {
    return data[row][col];
    * JTable uses this method to determine the default renderer/
    * editor for each cell. If we didn't implement this method,
    * then the last column would contain text ("true"/"false"),
    * rather than a check box.
    public Class getColumnClass(int c) {
    return getValueAt(0, c).getClass();
    * Don't need to implement this method unless your table's
    * editable.
    public boolean isCellEditable(int row, int col) {
    //Note that the data/cell address is constant,
    //no matter where the cell appears onscreen.
    return true;
    * Don't need to implement this method unless your table's
    * data can change.
    public void setValueAt(Object value, int row, int col) {
    if (DEBUG) {
    System.out.println("Setting value at " + row + "," + col
    + " to " + value
    + " (an instance of "
    + value.getClass() + ")");
    if (data[0][col] instanceof Integer
    && !(value instanceof Integer)) {                 
    //With JFC/Swing 1.1 and JDK 1.2, we need to create
    //an Integer from the value; otherwise, the column
    //switches to contain Strings. Starting with v 1.3,
    //the table automatically converts value to an Integer,
    //so you only need the code in the 'else' part of this
    //'if' block.
    //XXX: See TableEditDemo.java for a better solution!!!
    try {
    data[row][col] = new Integer(value.toString());
    fireTableCellUpdated(row, col);
    } catch (NumberFormatException e) {
    JOptionPane.showMessageDialog(TableDemo.this,
    "The \"" + getColumnName(col)
    + "\" column accepts only integer values.");
    } else {
    data[row][col] = value;
    fireTableCellUpdated(row, col);
    if (DEBUG) {
    System.out.println("New value of data:");
    printDebugData();
    private void printDebugData() {
    int numRows = getRowCount();
    int numCols = getColumnCount();
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + data[i][j]);
    System.out.println();
    System.out.println("--------------------------");
    private void createButtons() {
    // create panel to hold buttons
    buttonPanel = new JPanel();
    JButton buttonOK = new JButton("OK");
    buttonOK.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    // detect if a value was edited when OK was pressed without entering
    // return or changing focus
    if (table.isEditing()) {
    System.out.println("****** Table is edited ******");
    // value was edited when OK was pressed without entering return
    // or changing focus
    int row = table.getEditingRow();
    int column = table.getEditingColumn();
    System.out.println("row: " + row + ", column: " + column + " is edited");
    buttonPanel.add(buttonOK);
    public static void main(String[] args) {
    TableDemo frame = new TableDemo();
    frame.pack();
    frame.setVisible(true);

  • I want to run a streaming quotes program on Scottrade. They tell me that their product does not work if I have more than one Java application on my Mac. How do I delete the older versions? Thanks

    I want to run a streaming quotes program on Scottrade. They tell me that their product does not work if I have more than one Java application on my Mac. How do I delete the older versions? Thanks

    I have the same problem, they never told me that, just that the newest version of Java "locks" up streaming quotes.

  • Java.io.File renameTo does not work on Solaris

    Hi Experts,
    I have a code-piece which tries to move files from one directory to another on the SAME FILE SYSTEM using java.io.File.renameTo method.
    It works fine when there less no. of files in the source directory. But the renameTo does not work as expected when there are very huge no. of files(~40K) present in the source directory.
    I am aware that there is a known issue when one tries to use this method to move files across file systems OR if the file exists at the destination directory.
    But in my case the file system is the same and the there is no such file in the destination directory.
    I suspect some inode related issues. But not sure what it is exactly.
    Is there any limitations of renameTo?
    Please help.

    OK, we all now understand you have a problem in doing this, but without the specifics of the problem that you are experiencing, then it is fairly difficult to give you anything other than a guess. If you would like some specific and relevent answers, please supply specifics about how exactly the operation differs from your expected results. You should also post example code as it is almost always asked for eventually.

Maybe you are looking for