JButton NullPointerException problem

Hi
I was wondering if you guys can help me out on this one. I'm been prompted with a NullPointerException whenever I click on either of the 2 buttons.
Thanks guys
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Alarm extends JPanel implements ActionListener{
    private JTextArea messageField;
    private JButton alarmOn, alarmOff;
    private JLabel alarmLED;
    public Alarm(){
        super.setPreferredSize(new Dimension(200,300));
        //configuring components;
        JButton alarmOn = new JButton("On");
        alarmOn.addActionListener(this);
        JButton alarmOff = new JButton("OFF");
        alarmOff.addActionListener(this);
        JLabel alarmLED = new JLabel("Alarm OFF");
        alarmLED.setOpaque(true);
        alarmLED.setBackground(Color.GREEN);
        messageField = new JTextArea(2,20);
        messageField.setEditable(false);
        messageField.setPreferredSize(new Dimension(200, 200));
        this.add(messageField, BorderLayout.PAGE_START);
        alarmOn.setPreferredSize(new Dimension(80, 20));
        this.add(alarmOn, BorderLayout.LINE_START);
        alarmOff.setPreferredSize(new Dimension(80, 20));
        this.add(alarmOff, BorderLayout.CENTER);
        alarmLED.setPreferredSize(new Dimension(65, 30));
        this.add(alarmLED, BorderLayout.LINE_END);
     public void actionPerformed(ActionEvent event){
        if(event.getSource()==this.alarmOn){
            this.alarmLED.setBackground(Color.RED);
            this.alarmLED.setText("Alarm ON");
        }else{
            this.alarmLED.setBackground(Color.GREEN);
            this.alarmLED.setText("Alarm OFF");
}//end of class;

I figured it out...I think i declared the button twice.
Funny...it seems easier to spot it in this forums comparing it on BlueJ
Will someone recommend me a better java client then BLueJ?
Preferably user friendly kinds
Thanks

Similar Messages

  • JButton.setBackground() Problem

    Hi All,
    When i apply the setBackground() Method to a JButton to set its Background, i face i Problem :
    Under Mac Os : The JButton DOSE NOT change its color,
    when i take my code to my other computer under Windows : OK, the JButton change...
    i am wondering ....
    1) Why under my Mac OS i face this problem...
    2) and Why i get two different results from a same code ??? Java is not Portable?? and independant of the OS?? or it is the swing that makes the problem???
    My code is so simple :
    MyJButton.setBackground(new Color(255,100,100));
    Thanks to any help...

    ellias2007 wrote:
    Sorry because it is the first time for me in this forum....
    thanks for any help...
    Sorry againMost of us don't like disjointed discussions or repeating effort for a problem that has already been solved elsewhere. Thanks for your reply. A link to one discussion: [http://www.java-forums.org/awt-swing/25986-jbutton-setbackground-problem.html]
    If you have cross-posts elsewhere, please post links in all of them to each other or to one central location.

  • Java.lang.NullPointerException problem after installation

    Dear all,
    after i install the EP6.0 SP9 on AIX 5.3 ORACLE 9.2 ,when i want to create role ,i hit the IE error message like "operation aborted" .in the log viewer i found the error
    Time : 16:26:50:119
    Category : /System/Server
    Date : 06/22/2005
    Message :  [com.sapportals.portal.pcd.admintools.roleeditor.RoleEditorCompContextHandler] getPriority() failed
    [EXCEPTION]
    java.lang.NullPointerException
    at com.sapportals.portal.pcd.admintools.roleeditor.RoleEditorJndi.getPriority(RoleEditorJndi.java:1622)
    at com.sapportals.portal.pcd.admintools.roleeditor.RoleEditorJsTree.createTreeNode(RoleEditorJsTree.java:784)
    at com.sapportals.portal.pcd.admintools.roleeditor.RoleEditorJsTree.getChildTreeNodes(RoleEditorJsTree.java:646)
    at com.sapportals.portal.pcd.admintools.roleeditor.RoleEditorJsTree.createJScriptTree(RoleEditorJsTree.java:96)
    at com.sapportals.portal.pcd.admintools.roleeditor.RoleEditorJsTree.createJScriptTree(RoleEditorJsTree.java:106)
    at com.sapportals.portal.pcd.admintools.roleeditor.RoleEditorJsTree.buildRoleEditorJsTree(RoleEditorJsTree.java:56)
    at com.sapportals.portal.pcd.admintools.roleeditor.misc.RoleEditorPage2.createContentStudioPage2(RoleEditorPage2.java:1501)
    at com.sapportals.portal.pcd.admintools.roleeditor.misc.RoleEditorPage2.createPage2(RoleEditorPage2.java:1425)
    at com.sapportals.portal.pcd.admintools.roleeditor.RoleEditorMain.doContent(RoleEditorMain.java:129)
    at com.sapportals.portal.prt.component.AbstractPortalComponent.serviceDeprecated(AbstractPortalComponent.java:209)
    at com.sapportals.portal.prt.component.AbstractPortalComponent.service(AbstractPortalComponent.java:114)
    at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
    at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
    at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189)
    at com.sapportals.portal.prt.component.PortalComponentResponse.include(PortalComponentResponse.java:215)
    at com.sapportals.portal.prt.pom.PortalNode.service(PortalNode.java:646)
    at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)
    at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:136)
    at com.sapportals.portal.prt.core.PortalRequestManager.dispatchRequest(PortalRequestManager.java:189)
    at com.sapportals.portal.prt.core.PortalRequestManager.runRequestCycle(PortalRequestManager.java:753)
    at com.sapportals.portal.prt.connection.ServletConnection.handleRequest(ServletConnection.java:232)
    at com.sapportals.portal.prt.dispatcher.Dispatcher$doService.run(Dispatcher.java:522)
    at java.security.AccessController.doPrivileged1(Native Method)
    it seems to be java problem ,anybody could give some suggestion?thanks

    Hi,
    I have similar problem.
    If you have solved this issue please let me know how.
    Thanks
    Arun

  • NullPointerException problem when  deploying hello1 example.

    I am running Sun AppServer Edition 8.0 on Windows 2000 platform. When I
    executed asant build command, Build Successful message was displayed.
    To configure the Web application, I followed the steps outlined on how
    to package the application using the deploytool in Chapter 3 of the
    tutorial. Again I used the steps outlined on how to deploy the
    packaged web module using the deploytool to deploy the application
    on the Sun AppServer. However the deployment failed with
    NullPointerException message.
    Here is a listing of the error message:
    DetailsTimestamp:Nov 30, 2004 08:13:41.174
    Log Level: WARNING
    Logger:javax.enterprise.system.tools.admin
    Name-Value Pairs:_ThreadID=11;
    Record Number:106
    Message ID:ADM1026
    Complete Message
    Redeployment failed - Detailed Message:java.lang.NullPointerException     at
    com.sun.enterprise.admin.mbeans.ApplicationsConfigMBean.getHostName(ApplicationsConfigMBean.java:3045)     at
    com.sun.enterprise.admin.mbeans.ApplicationsConfigMBean.setHostAndPort(ApplicationsConfigMBean.java:3038)     at
    com.sun.enterprise.admin.mbeans.ApplicationsConfigMBean.deploy(ApplicationsConfigMBean.java:274)     at
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)     at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     at
    java.lang.reflect.Method.invoke(Method.java:324)     at
    com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:287)     at
    com.sun.enterprise.admin.config.BaseConfigMBean.invoke(BaseConfigMBean.java:280)     at
    com.sun.jmx.mbeanserver.DynamicMetaDataImpl.invoke(DynamicMetaDataImpl.java:221)     at
    com.sun.jmx.mbeanserver.MetaDataImpl.invoke(MetaDataImpl.java:228)     at
    com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:823)     at
    com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:792)     at
    sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)     at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     at
    java.lang.reflect.Method.invoke(Method.java:324)     at
    com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:54)     at $Proxy1.invoke(Unknown Source)     at
    com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInterceptor.java:282)     at
    com.sun.enterprise.admin.jmx.remote.server.callers.InvokeCaller.call(InvokeCaller.java:38)     at
    com.sun.enterprise.admin.jmx.remote.server.MBeanServerRequestHandler.handle(MBeanServerRequestHandler.java:92)     at
    com.sun.enterprise.admin.jmx.remote.server.servlet.RemoteJmxConnectorServlet.processRequest(RemoteJmxConnectorServlet.java:
    69)     at
    com.sun.enterprise.admin.jmx.remote.server.servlet.RemoteJmxConnectorServlet.doPost(RemoteJmxConnectorServlet.java:94)     at
    javax.servlet.http.HttpServlet.service(HttpServlet.java:768)     at
    javax.servlet.http.HttpServlet.service(HttpServlet.java:861)     at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown
    Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)     at
    java.lang.reflect.Method.invoke(Method.java:324)     at
    org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:289)     at
    java.security.AccessController.doPrivileged(Native Method)     at
    javax.security.auth.Subject.doAsPrivileged(Subject.java:500)     at
    org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:311)     at
    org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:205)     at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:283)     at
    org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:102)     at
    org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:192)     at
    java.security.AccessController.doPrivileged(Native Method)     at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)     at
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:263)     at
    org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:156)     at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:569)     at
    org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:261)     at
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:215)     at
    org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:156)     at
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:583)     at
    org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)     at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:569)     at
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:200)     at
    org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:156)     at
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:180)     at
    org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)     at
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:582)     at
    org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)     at
    com.sun.enterprise.webservice.EjbWebServiceValve.invoke(EjbWebServiceValve.java:134)     at
    org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)     at
    com.sun.enterprise.security.web.SingleSignOn.invoke(SingleSignOn.java:254)     at
    org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)     at
    com.sun.enterprise.web.VirtualServerValve.invoke(VirtualServerValve.java:209)     at
    org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)     at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:569)     at
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:161)     at
    org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:156)     at
    com.sun.enterprise.web.VirtualServerMappingValve.invoke(VirtualServerMappingValve.java:166)     at
    org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:154)     at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:569)     at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:979)     at
    org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:211)     at
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:692)     at
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:647)     at
    org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)     at
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:691)     at
    java.lang.Thread.run(Thread.java:534)
    Here is the output from asant listprops command.
    Buildfile: build.xml
    listprops:
    [echo] Path information
    [echo] j2ee.home = C:/Sun/AppServer
    [echo] env.Path = .;
    c:\oracle\ora92\bin;
    c:\oracle\ora92\sqlj\bin;
    C:\Program Files\Oracle\jre\1.3.1\bin;
    C:\Program Files\Oracle\jre\1.1.8\bin;
    C:\Ant\apache-ant-1.6.2\bin;
    C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Program Files\Microsoft SQL
    Server\80\Tools\Binn\;
    c:\mysql\bin;
    c:\j2sdk1.4.2_06\bin;
    c:\Sun\AppServer\bin;
    c:\Sun\AppServer\bin;c:\Sun\AppServer\jdk\bin;
    C:\Documents and Settings\sam darko\jwsdp-1.1\jwsdp-shared\bin;
    C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;
    C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual
    Studio\Common\Tools;
    C:\Program Files\Microsoft Visual Studio\VC98\bin;
    C:\Program Files\MSXML 4.0;
    C:\Ant\apache-ant-1.6.2\bin;
    c:\mysql\bin;
    c:\bea\weblogic81\server\bin;
    C:\;
    C:\ERCDTMP;C:\ERCDTMP\BIN;C:\ERCDTMP\TOOLS\PT1
    [echo] env.PATH = ${env.PATH}
    [echo] Classpath information
    [echo] classpath = .;
    c:\Sun\AppServer\lib\j2ee.jar;
    c:\Sun\AppServer\jdk\lib\tools.jar;
    C:\Program Files\Altova\xmlspy\XMLSpyInterface.jar;
    c:\bea\weblogic81\server\lib\weblogic_sp.jar;
    c:\bea\weblogic81\server\lib\weblogic.jar;
    C:\jakarta-struts-1.1\lib\struts.jar;
    c:\JSTL1.1\jstl-1.1.2\lib\jstl.jar;
    c:\JSTL1.1\jstl-1.1.2\lib\standard.jar
    [echo] Admin information
    [echo] admin.password = ${admin.password}
    [echo] admin.host = localhost
    [echo] admin.user = admin
    [echo] admin.port = 4848
    [echo] https.port = 8090
    [echo] Domain information
    [echo] domain.resources = "domain.resources"
    [echo] domain.resources.port = 8091
    [echo] Database information
    [echo] db.root = C:/Sun/AppServer/pointbase
    [echo] db.driver = com.pointbase.jdbc.jdbcUniversalDriver
    [echo] db.host = localhost
    [echo] db.port = 9092
    [echo] db.sid = sun-appserv-samples
    [echo] db.url = jdbc:pointbase:server://localhost:9092/sun-appserv-samples
    [echo] db.user = pbpublic
    [echo] db.pwd = pbpublic
    [echo] url.prop = DatabaseName
    [echo] ds.class = com.pointbase.jdbc.jdbcDataSource
    [echo] db.jvmargs = -ms16m -mx32m
    BUILD SUCCESSFUL
    Total time: 5 seconds

    I just ran the hello1 example on a Win2K system from the command line without seeing the problems that you encountered. I am running a later version of the Application Server than you are (8.1 PE vs. 8.0) and am using the tutorial sources that were designed to be used with that version of the tutorial:
    - Use Update 3 version of the tutorial with Application Server 8.1
    - Use Update 2 version of the tutorial with Application Server 8.0 Update 1
    I haven't tried it with deploytool yet, but built, packaged, and deployed using the asant instructions, as follows.
    1. Start the Application Server.
    2. In a terminal window, change to the j2eetutorial14/examples/web/hello1 directory.
    3. Build the example: asant build
    4. Package the example: asant create-war
    5. Deploy the example: asant deploy-war
    6. In your browser, go to http://localhost:8080/hello1and enter your name.
    If you do this do you see the same problem? If you do, where do you encounter that problem? On deployment?
    In the meantime, I'll try to package and deploy with deploytool and report back with my results.
    Hope this helps.
    ~Eric

  • How can I can solve my NullPointerException problem?

    Hi all,
    So I'm playing around with some code and was wondering why I get the following?
    Exception in thread "main" java.lang.NullPointerException
         at lecture_examples.Library.searchForTitle(Library.java:38)
         at lecture_examples.LibraryManager.main(LibraryManager.java:24)The problem seems to occur when I call searchForTitle() in the library class. Here is my code:
    package lecture_examples;
    public class LibraryManager
         public static void main(String []args)
              Library lib = new Library(150);
              Book book1 = new Book("Africa", "Ray Mears", "1111-1111-1111-1", "Penguin Books", 2007);
              Book book2 = new Book("North America", "Ray Mears", "2222-2222-2222-2", "Penguin Books", 2007);
              Book book3 = new Book("South America", "Ray Mears", "3333-3333-3333-3", "Penguin Books", 2007);
              Book book4 = new Book("Europe", "Ray Mears", "4444-4444-4444-4444-4", "Penguin Books", 2007);
              Book book5 = new Book("Asia", "Ray Mears", "5555-5555-5555-5555-5", "Penguin Books", 2007);
              Book book6 = new Book("Australasia", "Ray Mears", "6666-6666-6666-6666-6", "Penguin Books", 2007);
              Book book7 = new Book("India", "Ray Mears", "7777-7777-7777-7", "Penguin Books", 2007);
              Book book8 = new Book("South Pacific", "Ray Mears", "8888-8888-8888-8", "Penguin Books", 2007);
              lib.addBook(book1);
              lib.addBook(book2);
              lib.addBook(book3);
              lib.addBook(book4);
              lib.addBook(book5);
              lib.addBook(book6);
              lib.addBook(book7);
              lib.addBook(book8);
              lib.searchForTitle("India");
         //other static methods used by main
    package lecture_examples;
    import java.util.Vector;
    public class Library
         private int currSize = 0;
         private Book[] books;
         public Library()
              books=new Book[1000];
         public Library(int maxSize)
              books=new Book[maxSize];
         public void addBook(Book newBook)
              if(currSize<books.length) //if there the book array is not full
                   books[currSize++]=newBook;//Puts the newBook into an element of book array
              else
                   System.out.println("Your Library is Full");//Output error message
         public Book[] searchForTitle(String aTitle)
              Vector v=new Vector();//create an expandable Vector called v.
              for(int i=0;i<books.length;i++)//loops through the array of books
                   if(aTitle.equals(books.getTitle()))//compares the searched Title with each title stored in each element of the book array
                        v.add(books[i]);//if the book lexigraphically matches a book in the book array it adds the existing book to the vector
              Book[] results=new Book[v.size()];//creates an book-result array which is the same size as the vector
              for(int i=0;i<v.size();i++)
                   results[i]=(Book)(v.elementAt(i)); //loops through the results vector and casts them as books into the book array
              return results;     //returns results     
         public void removeBook(String isbn)
              int index=getIndex(isbn);//gets the index of isbn and assigns it to the index integer variable
              for (int i=index;i<currSize-1;i++) //loops through the books
                   books[i]=books[i+1]; //moves each book up one element in the book array
              currSize--;//decrements the number of books in the library
         public int getIndex(String isbn)
              int index = 0;
              for(int i=0;i<currSize;i++)//loops through the number of books
                   if(isbn.equals(books[i].getIsbn()))//If the isbn is in the book array
                        index = i; //assign index to i
              return index;
    package lecture_examples;
    public class Book
         private String title = "Invalid";
         private String author = "Invalid";
         private String isbn = "Invalid";
         private String publisher = "Invalid";
         private int publicationYear = 0000;
         public Book(String title, String author, String isbn, String publisher, int publicationYear)
              this.title = title;
              this.author = author;
              this.isbn = isbn;
              this.publisher = publisher;
              this.publicationYear = publicationYear;          
         public String getTitle()
              return title;
         public String getAuthor()
              return author;
         public String getIsbn()
              return isbn;
         public String getPublisher()
              return publisher;
         public int getPublicationYear()
              return publicationYear;
         public void setTitle(String newTitle)
              title = newTitle;
         public void setAuthor(String newAuthor)
              author = newAuthor;
         public void setisbn(String newisbn)
              isbn = newisbn;
         public void setPublisher(String newPublisher)
              publisher = newPublisher;
         public void setPublicationYear(int newPublicationYear)
              publicationYear = newPublicationYear;
         public String toString()
              String fullDetails = "\nTitle = \t" + title
              + "\nAuthor = \t" + author
              + "\nISBN = \t\t" + isbn
              + "\nPublisher = \t" + publisher
              + "\nYear = \t\t" + publicationYear;
              System.out.println(fullDetails);
              return fullDetails;

    >
    Exception in thread "main" java.lang.NullPointerException
         at lecture_examples.Library.searchForTitle(Library.java:38)
         at lecture_examples.LibraryManager.main(LibraryManager.java:24)Simple, line #38 in your Library.java in giving you NullPointerException. In the constructor of your Library.java, you are creating books array of size 1000, which will be initialized to an Books array with 1000 null values. Are you having a reference to a Book object at all 1000 array positions? If no, then in your searchForTitle() method you are iterating through the entire books array using a for loop and at every array object you are calling books.getTitle(). But, if your array has null values then it will throw NullPointerException. So do something like this...
    if(books!=null && aTitle.equals(books[i].getTitle()))//compares the searched Title with each title stored in each element of the book array
                        v.add(books[i]);//if the book lexigraphically matches a book in the book array it adds the existing book to the vector

  • JButton imageIcon problem

    hello ,
    i am facing a problem in changing the imageicon of jbutton in my application.
    i want to change imageicon for few seconds and than again change it to original imageicon....
    is it possible?????????????i have tried but after initializing button with one imageicon we are not able to change that icon again..
    so what should i do...it is compulsory to change take two image for button.....
    please help

    Set up a Timer. You use the setIcon(...) method to change the icon. Then you start a Timer to fire in a few seconds and use the setIcon(...) method to change the image back to its original value.

  • JButton dispatchEvent problem

    Hi,
    I've got JButtons in a JTable which means I have to capture the mouse events and forward them to the button.
    I do this with a mouse listener on the table, and the lines:
    buttonEvent = (MouseEvent)SwingUtilities.convertMouseEvent(table, e, button);
    button.dispatchEvent(buttonEvent);
    System.out.println(buttonEvent);
    table.repaint();where 'e' is the original mouse event. This produces, for example:
    java.awt.event.MouseEvent[MOUSE_CLICKED,(145,167),button=1,modifiers=Button1,clickCount=1]
    on
    javax.swing.JButton[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=0.5 <snip> text=Delete,defaultCapable=true]but yet nothing happens to the button. Is this a coordinate problem, or am I missing something else, as I don't really know what I'm doing?
    Cheers,
    Rob

    MOUSE_CLICKED,(145,167),Well I'm guessing that you can't just convert the table coordinates and use them as the button coordinates because the button isn't that big.
    An alternative approach might be to use the doClick() method of the button.
    In case that doesn't work, here's something I've been playing with that may help:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TableButton3 extends JFrame
         public TableButton3()
              String[] columnNames = {"Date", "String", "Integer", "Decimal", ""};
              Object[][] data =
                   {new Date(), "A", new Integer(1), new Double(5.1), "Delete1"},
                   {new Date(), "B", new Integer(2), new Double(6.2), "Delete2"},
                   {new Date(), "C", new Integer(3), new Double(7.3), "Delete3"},
                   {new Date(), "D", new Integer(4), new Double(8.4), "Delete4"}
              DefaultTableModel model = new DefaultTableModel(data, columnNames);
              JTable table = new JTable( model )
                   //  Returning the Class of each column will allow different
                   //  renderers to be used based on Class
                   public Class getColumnClass(int column)
                        return getValueAt(0, column).getClass();
              JScrollPane scrollPane = new JScrollPane( table );
              getContentPane().add( scrollPane );
              //  Create button column
              ButtonColumn buttonColumn = new ButtonColumn(table, 4);
         public static void main(String[] args)
              TableButton3 frame = new TableButton3();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.pack();
              frame.setVisible(true);
         class ButtonColumn extends AbstractCellEditor
              implements TableCellRenderer, TableCellEditor, ActionListener
              JTable table;
              JButton renderButton;
              JButton editButton;
              String text;
              public ButtonColumn(JTable table, int column)
                   super();
                   this.table = table;
                   renderButton = new JButton();
                   editButton = new JButton();
                   editButton.setFocusPainted( false );
                   editButton.addActionListener( this );
                   TableColumnModel columnModel = table.getColumnModel();
                   columnModel.getColumn(column).setCellRenderer( this );
                   columnModel.getColumn(column).setCellEditor( this );
              public Component getTableCellRendererComponent(
                   JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
                   if (hasFocus)
                        renderButton.setForeground(table.getForeground());
                         renderButton.setBackground(Color.WHITE);
                   else if (isSelected)
                        renderButton.setForeground(table.getSelectionForeground());
                         renderButton.setBackground(table.getSelectionBackground());
                   else
                        renderButton.setForeground(table.getForeground());
                        renderButton.setBackground(UIManager.getColor("Button.background"));
                   renderButton.setText( (value == null) ? "" : value.toString() );
                   return renderButton;
              public Component getTableCellEditorComponent(
                   JTable table, Object value, boolean isSelected, int row, int column)
                   text = (value == null) ? "" : value.toString();
                   editButton.setText( text );
                   return editButton;
              public Object getCellEditorValue()
                   return text;
              public void actionPerformed(ActionEvent e)
                   fireEditingStopped();
                   System.out.println( "Action: " + e.getActionCommand() );
    }

  • NullPointerException problems.....

    Hi All,
    I am having a serious disagreement with some NullPointerExceptions, in my case unfortunately I cannot simply wrap the code causing the exceptions in in a try{ catch{ block as this will completely shut my application down before it even has a chance to do anything!
    To start with I create a number of ButtonData objects from the following code:
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    public class Begin
      public static JTextField ExecT;   
      public static JTextField LinkName;
      public static String Path1;
      public static String Path2;
      public static String Path3;
      public static String Path4;
      public static String Path5;
      public static Container c;
      public static JButton button1;
      public static JButton button2;
      public static JButton button3;
      public static JButton button4;
      public static JButton button5;
      public static DataEntryBox EntryBox;
      public static ButtonData BtData1;
      public static ButtonData BtData2;
      public static ButtonData BtData3;
      public static ButtonData BtData4;
      public static ButtonData BtData5;
      public static FileInputStream inStream;      //Incoming object stream.
      public static ObjectInputStream objStreamIn;
      public static FileOutputStream outStream;    //Outgoing object stream.
      public static ObjectOutputStream objStreamOut;
      public static void main(String[] args)
        try{
          inStream = new FileInputStream("ObjStore");
          objStreamIn = new ObjectInputStream(inStream);
          if(objStreamIn.available() == 0)   //Check for objects in file.
            objStreamIn.close();        //Close incoming object / file
            inStream.close();           //streams as no objects were found.
        //Instantiate ButtonData objects only once, when program is first
        //run, and never again unless the "ObjStore" file has been deleted.
            BtData1 = new ButtonData();
            BtData1.initName("Link1");
            BtData1.initPath("");
            BtData2 = new ButtonData();
            BtData2.initName("Link2");
            BtData2.initPath("");
            BtData3 = new ButtonData();
            BtData3.initName("Link3");
            BtData3.initPath("");
            BtData4 = new ButtonData();
            BtData4.initName("Link4");
            BtData4.initPath("");
            BtData5 = new ButtonData();
            BtData5.initName("Link5");
            BtData5.initPath("");
          else
            try{
            Begin.BtData1 = (ButtonData)objStreamIn.readObject();
            Begin.BtData2 = (ButtonData)objStreamIn.readObject();
            Begin.BtData3 = (ButtonData)objStreamIn.readObject();
            Begin.BtData4 = (ButtonData)objStreamIn.readObject();
            Begin.BtData5 = (ButtonData)objStreamIn.readObject();
            }catch(ClassNotFoundException e){}
            objStreamIn.close();          //Close streams after all objects
            inStream.close();             //have been read from file.
        }catch(IOException e){}
        GUI xyz = new GUI();             //Create the General User
                                         //Interface.
    }This program utilises object serialization and the ButtonData objects are defined by this class:
    import java.io.*;
    public class ButtonData implements Serializable
      private String Name;     //Holds TextField Name details for JButtons.
      private String Path;     //Holds Path details for JButtons.
      public void initName(String Name)
        this.Name = Name;
      public void initPath(String Path)
        this.Path = Path;
      public String getName()
        return Name;
      public String getPath()
        return Path;
      public void setName()
        Name = Begin.LinkName.getText();
      public void setPath()
        Path = Begin.ExecT.getText();
    }All of the above code compiles and runs fine, however it is when the following code is reached that NullPointerExceptions are thrown.
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class GUI extends JFrame implements ActionListener
      FrameListener GUIListener = new FrameListener();  //Listener object created.
      GUI()
        JMenuItem AboutItem = new JMenuItem("About",KeyEvent.VK_A);
        HMenu.add(AboutItem);
        AboutItem.addActionListener(this);
        Begin.button1 = new JButton();
        d.weightx = 0.2; 
        d.weighty = 0.3; 
        d.gridx = 0;     
        d.gridy = 0;     
        gridbag2.setConstraints(Begin.button1, d);
        Begin.c.add(Begin.button1);
        try{
        Begin.button1.setText(Begin.BtData1.getName());
        Begin.Path1 = Begin.BtData1.getPath();
        }catch(NullPointerException e){}
        Begin.button2 = new JButton();
        d.weightx = 0.2; 
        d.weighty = 0.3; 
        d.gridx = 1;     
        d.gridy = 0;     
        gridbag2.setConstraints(Begin.button2, d);
        Begin.c.add(Begin.button2);
        //try{
        Begin.button2.setText(Begin.BtData2.getName());
        Begin.Path2 = Begin.BtData2.getPath();
        //}catch(NullPointerException e){}
        Begin.button3 = new JButton();
        d.weightx = 0.2; 
        d.weighty = 0.3; 
        d.gridx = 2;     
        d.gridy = 0;     
        gridbag2.setConstraints(Begin.button3, d);
        Begin.c.add(Begin.button3);
        //try{
        Begin.button3.setText(Begin.BtData3.getName());
        Begin.Path3 = Begin.BtData3.getPath();
        //}catch(NullPointerException e){}
        Begin.button4 = new JButton();
        d.weightx = 0.2; 
        d.weighty = 0.3; 
        d.gridx = 3;     
        d.gridy = 0;     
        gridbag2.setConstraints(Begin.button4, d);
        Begin.c.add(Begin.button4);
        //try{
        Begin.button4.setText(Begin.BtData4.getName());
        Begin.Path4 = Begin.BtData4.getPath();
        //}catch(NullPointerException e){}
        Begin.button5 = new JButton();
        d.weightx = 0.2; 
        d.weighty = 0.3; 
        d.gridx = 4;     
        d.gridy = 0;     
        gridbag2.setConstraints(Begin.button5, d);
        Begin.c.add(Begin.button5);
        //try{
        Begin.button5.setText(Begin.BtData5.getName());
        Begin.Path5 = Begin.BtData5.getPath();
        //}catch(NullPointerException e){}
        Begin.button1.addActionListener(this);
        Begin.button2.addActionListener(this);
        Begin.button3.addActionListener(this);
       }The code segment above shows //try and //catch commented out. With try and catch included in the above locations I can intercept the exceptions however this flaws my program completely. My question is why do the two lines between the try and catch blocks throw NullPointerExceptions? Is it because the objects don't exist? --> That sounds silly to me because they were definitely instantiated in the first code snippet that I have supplied. What is going on...suggestions will be really appreciated.
    Thanks

    BTW: this is very poor coding style! You should avoid things like
    Begin.button1.addActionListener(this);
    instead use clean OO way like:
    Begin begin = new Begin();
    begin.setButton1ActionListener(this);
    avoid static fields wherever possible, use OO encapsulation by offering methods to change your class fields.
    and: don't use a capital letter as the first letter for your fields (BtData1 => btData1). and some other things. read the Java Coding Conventions:
    http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

  • Brain hurts, need help nullPointerException problems

    I've been working on this program almost 8 hours straight and have just hit my latest problem but I'm getting too tired to solve it tonight and thought someone might have some useful pointers.
    I have a screen that takes several details in text fields from the user and when the OK button is pressed does the following:
    private void okButtonActionPerformed(ActionEvent evt)
    ConfirmTitlePanel confirmTitlePanel = new ConfirmTitlePanel();
    . // Gets details from text fields here
    model.Title.newInstance( param1,
    param2,
    etc... );
    // Fetch reference to Graphical so buttons can use it to
    // display panels
    graph = model.Shop.getGraphical();
    graph.display( confirmTitlePanel );
    This displays the next panel which works fine on its own but when I add the code to get the details I've just set with newInstance, so I can display them back to the user I get a NullPointerException.
    My set code is called when initialising the panel and looks like this:
    private void
    setValues() throws NullPointerException
    model.Field[] titleDetails = model.Title.getFullDetails();
    param1.setText( titleDetails[0].asString() );
    param2.setText( titleDetails[1].asString() );
    etc...
    Seems getFullDetails is not returning anything to titleDetails. Field is an array of things. It's set up to handle int, boolean and String. The asString determines the type of titleDetails[x] and converts it to a String. It is at the point where asString is trying to convert the first parameter it is determining the object type is null.
    I'm sure the answer is simple but I'm felling a bit fried so any help would be appreciated before I start afresh tomorrow.
    Thanks in advance.
    Regards,
    Mark.

    Please help if you can. I can send the full code directly to people if they wish.
    My problem is not so much setText as the fact when I read the values in the object instance I created they are null. I've found a interesting point though. I added debug lines and found that the newInstance had the correct values and the setObject created an object that was not null.
    However the first time you submit the details when it tries to get the object it is null. However when you try and enter the details for a second time it will display the details entered on your first entry. Likewise if you went to enter a third title and put blank details in it would display the second set of details back to the user when they click OK.
    Right onto the code.
    ----Shop.class - contains
    public static Object
    getObject()
    if ( save_ == null)
    System.out.println("Return save_ but it is null");
    return save_;
    public static void
    setObject( Object save )
    save_ = save;
    if ( save == null)
    System.out.println("Just taken save but it is null");
    if ( save_ == null)
    System.out.println("Just set save_ but it is null");
    ----AddTitlePanel.class contains
    private void okButtonActionPerformed(ActionEvent evt)
    ConfirmAddTitlePanel confirmAddTitlePanel =
    new ConfirmAddTitlePanel();
    // Gets the textField values here
    model.Title mss = model.Title.newInstance( fullISBN,
    ISBN,
    title,
    author,
    copiesInStock,
    price );
    model.Shop.setObject( mss );
    // Fetch reference to Graphical so buttons can use it to
    // display panels
    graph = model.Shop.getGraphical();
    graph.display( confirmAddTitlePanel );
    This creates a newInstance of Title and creates a copy using setObject when the user clicks on "OK" button. It also calls the ConfirmAddTitlePanel.class to display the details back to the user.
    ----ConfirmAddTitlePanel.class contains:
    private void
    setValues() throws NullPointerException
    model.Title mss = (model.Title) model.Shop.getObject();
    if ( mss != null )
    model.Field[] titleDetails = mss.getFullDetails();
    //model.Field[] titleDetails = model.Title.getFullDetails();
    fullISBNTextField.setText( titleDetails[0].asString() );
    //ISBNTextField.setText( titleDetails[1].asString() );
    titleTextField.setText( titleDetails[2].asString() );
    authorTextField.setText( titleDetails[3].asString() );
    copiesInStockTextField.setText( titleDetails[4].asString() );
    priceTextField.setText( titleDetails[5].asString() );
    else
    System.out.println( "\nMSS = null" );
    This is getting the Object back that we just set and fetching its details to display to the user by populating the TextFields.
    As I say first time you enter the details and click OK it displays the above panel and outputs "MSS = null" and cannot populate the fields. When you enter the next set of title details and click "OK" getObject is no longer setting mss to null but the values fetched to set the TextFields is the data entered for the first title and not the details just entered.
    ----Title.class contains:
    public static Title
    newInstance( String fullISBN,
    String ISBN,
    String title,
    String author,
    int copiesInStock,
    int price )
    Title atitle = new Title( fullISBN,
    ISBN,
    title,
    author,
    copiesInStock,
    price );
    System.out.println("Created new object instance Title\n");
    System.out.println( "FullISBN = " + getFullISBN() );
    System.out.println( "ISBN = " + getISBN() );
    System.out.println( "Title = " + getTitle() );
    System.out.println( "Author = " + getAuthor() );
    System.out.println( "Copies = " + getCopiesInStock() );
    System.out.println( "Price = " + getPrice() );
    return atitle;
    I'm really stuck and if I solve this I should hopefully be able to make progress again. Thanks in advance.
    Mark.

  • (homework) NullPointerException problem

    This is a homework problem that is asking us to go through two lists of names, find the duplicates between the two. Then we are supposed to take only the last names, sort them into ascending order and capitalize the entire name and print it. The problem is I get an NPE every time I add the following code:
    Arrays.sort(lastname);Example:
    import java.util.Arrays;
    public class NameLists2
       public static void main(String [] args)
              String [] names1 = {"Bill Board","John Smith","Smiley Faces","Hazel Nutt",
                                           "Al K Selzer","Wah Shuppe","June Schauer","Simon Sez",
                                            "Justin Time","Fast Walker","Ima Legend","Garren Teed",
                                   "Skip Roper","Hy Price","Shanda Lear","Bill Foldes",
                                    "James Bond","Stu Meat","Mike Raffone","Budd Weiser"};
            String [] names2 = {"Rick Shaw","Smiley Faces","Seymour Faces","Al K Selzer",
                                      "Sandy Beach","June Schauer","Luce Change","Mae Flowers",
                                 "Justin Time","Iona Honda","Budd Weiser","Stu Meat",
                               "Bill Board","Phil R Uppe","Bill Foldes","Ben Dover",
                                "Snough Storm","James Bond","Mike Raffone","Hazel Nutt"};
             String [] lastname = new String [20];
             int loc;
               for(int i = 0; i < names1.length; i++)
                    for(int j = 0; j < names2.length; j++)
                       if(names1.compareTo(names2[j]) == 0)
                   loc = names1[i].indexOf(' ');
                   lastname[i] = names1[i].substring(loc + 1);
                   Arrays.sort(lastname);
    System.out.println(lastname[i]);
    Exception in thread "main" java.lang.NullPointerException
         at java.lang.String.compareTo(String.java:1168)
         at java.lang.String.compareTo(String.java:92)
         at java.util.Arrays.mergeSort(Arrays.java:1144)
         at java.util.Arrays.mergeSort(Arrays.java:1155)
         at java.util.Arrays.mergeSort(Arrays.java:1155)
         at java.util.Arrays.sort(Arrays.java:1079)
         at NameLists2.main(NameLists2.java:35)
    I've read up on NPEs and I still can't figure out where I'm screwing up, any ideas?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    The reason you are getting that error is because when you created the array String [] lastname = new String [20]; it makes all twenty entries equal to null therfore the method cannot sort through null entries heres what you do.
    Changes i would make
    int count=0;
    String [] lastname,temp = new String [20];
    for(int i = 0; i < names1.length; i++)
                   for(int j = 0; j < names2.length; j++)
                   if(names1.equal(names2[j]))
                   loc = names1[i].indexOf(' ');
    temp[count] = names[i].substring(loc + 1);
                   count++;
    lastname=new String [count]
    for (int x=0;x<count;x++){
    lastname[x]=temp[x];}
    Array.sort(lastname);
    for (int x=0;x<count;x++){
    System.out.println(lastname[i]);}
    Edited by: Wyatt on Feb 12, 2008 10:41 AM

  • JButton display problem

    I would have thought the following would bring up two identical MainWindows, but in fact the buttons in the second one look slightly different.
    public class Main {
         public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                     setUpApp();
         private static void setUpApp() {
              MainWindow mainWindow = new MainWindow();
              MainWindow mainWindow2 = new MainWindow();
    }This is what the two windows look like after display: (How do URLs work?)
    I'm not really sure what code to paste other than this because I would think the code is identical for both.

    Slow day, and I actually created an SSCCE:
    import javax.swing.*;
    import java.awt.*;
    public class MainWindow {
       private JFrame topLevelContainer;
       public MainWindow() {
          topLevelContainer = new JFrame();
          topLevelContainer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          topLevelContainer.setPreferredSize(new Dimension(400, 400));
          Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
          topLevelContainer.setTitle("ChatApp");
          topLevelContainer.setVisible(true);
          JPanel contentPane = new JPanel(new BorderLayout(2, 2));
          contentPane.setBorder(BorderFactory.createLineBorder(Color.BLUE));
          contentPane.setBackground(Color.BLUE);
          topLevelContainer.setContentPane(contentPane);
          JPanel sendingTo = new JPanel();
          sendingTo.setOpaque(false);
          sendingTo.setBorder(BorderFactory.createTitledBorder("Sending To"));
          contentPane.add(sendingTo, BorderLayout.PAGE_START);
          JPanel messageLog = new JPanel();
          messageLog.setOpaque(false);
          messageLog.setBorder(BorderFactory.createTitledBorder("Message Log"));
          contentPane.add(messageLog, BorderLayout.CENTER);
          JPanel sendPanel = new JPanel(new BorderLayout(2, 0));
          sendPanel.setBackground(Color.BLUE);
          JTextArea sendMessageArea = new JTextArea("Send Message Area", 5, 30);
          sendMessageArea.setOpaque(false);
          sendPanel.add(sendMessageArea, BorderLayout.CENTER);
          JButton _sendMessage = new JButton("Send Message");
          sendPanel.add(_sendMessage, BorderLayout.LINE_END);
          contentPane.add(sendPanel, BorderLayout.PAGE_END);
          try {
             UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
          } catch (ClassNotFoundException e) {
             e.printStackTrace();
          } catch (InstantiationException e) {
             e.printStackTrace();
          } catch (IllegalAccessException e) {
             e.printStackTrace();
          } catch (UnsupportedLookAndFeelException e) {
             e.printStackTrace();
          topLevelContainer.pack();
       private static void createAndShowUI() {
          new MainWindow();
          new MainWindow();
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
    }And in it, I notice that you're setting your GUI visible before adding components and your setting the look and feel after you've created and added components, and this seems a bit backwards. The look and feel issue is what is causing the problem that you are noticing.

  • JButton Adding Problem

    Hi everyone,
    First, like to say I appreciate all your help. I have come here for help before and I always get my questions answered. Thanks.
    Here is my problem:
    I've created a JPanel and added this panel to a JFrame. The JPanel has a MouseListener and a MouseMotionListener. I am tryin to add JButtons to the JPanel at positions passed from the MouseMotionListener, but everytime I attempt this, the JButton pops to the top left corner of the screen. I don't know if I should use a layout manager on the JPanel and if I do, I don't know which one to use. I've tried using the SpringLayout, but was unsuccessful at deploying it.
    Appreciate any help.
    Thanks again.

    Null layout is not recommended, see my earlier post. Here is a simple SpringLayout that does the same thing.
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TestSpring extends JFrame
         Container cp;
         int mpx, mpy;
         int MINX= 80;
         int MINY=20;
         JLabel txt = new JLabel("use mouse to position buttons, drag to set size");
         SpringLayout slay = new SpringLayout();
         MouseInputAdapter mia = new MouseInputAdapter()
              public void mousePressed(MouseEvent evt){mousePress(evt);}
              public void mouseReleased(MouseEvent evt){mouseRelease(evt);}
         TestSpring()
              super("TestSpring");
              cp = getContentPane();
              addWindowListener(new WindowAdapter()
              {public void windowClosing(WindowEvent evt){System.exit(0);}});
              cp.addMouseListener(mia);
              cp.setLayout(slay);
              cp.add(txt);
              setBounds(0,0,700,400);
         void mousePress(MouseEvent evt)
              mpx = evt.getX();
              mpy = evt.getY();
         void mouseRelease(MouseEvent evt)
              int x,y,dx,dy;
              x = evt.getX();
              y=evt.getY();
              dx = x-mpx;
              dy = y-mpy;
              if(dx < 0){dx = -dx; mpx = x;}
              if(dy < 0){dy = -dy; mpy = y;}
              JButton jb = new JButton(mpx+","+mpy);
              cp.add(jb);
              setCPosition(jb,mpx,mpy);
              if(dx < MINX)dx = MINX;
              if(dy < MINY)dy = MINY;
              setCSize(jb, dx, dy);
              cp.validate();
         void setCPosition(Component c, int x, int y)
              slay.getConstraints(c).setX(Spring.constant(x));
              slay.getConstraints(c).setY(Spring.constant(y));
         void setCSize(Component c, int w, int h)
              slay.getConstraints(c).setWidth(Spring.constant(w));
              slay.getConstraints(c).setHeight(Spring.constant(h));
         // the main startup function
         public static void main(String[] args)
              new TestSpring().show();
    }

  • JButton clicked problem?

    I have a Jbutton and on button clicked, action is performed.
    Now if mouse is just clicked but moved only one pixel(means focus is still on the button) , action will not occur. It works only if the button is clicked and mouse does not move at all. I want action if the button is clicked and does not leave the button forground area until it is released.
    thnx

    Sounds like there is a problem in your code. Only can make wild guesses based on the lack of info. (If you post code, please spare us the pain of looking at all of it, just create a simple example).

  • JButton base problem

    Hi All,
    I have a primitive /as I known/ problem with the JButton.
    I create one, and set the text with this 'Show'. I set the font /eg. Arial/ and it's size to 9.
    If I set the required size of the button the text is not shown. /shown only .../
    When show the text correctly the width of button is very large for me.
    How can I make a button which hase a same width such as the text in it.?
    thx.

    Once you've set the font and text for a button, you can find out its preferred size using getPreferredSize.
    Typically buttons will add on padding between the text and the border. This is known as the "margin" and can be changed using setMargin.
    You can set the margin for all buttons using UIManager's Button.margin property.
    Hope this helps.

  • NullPointerException problem while importing MDL file......

    Hi OWB Gurus,
    I am getting java.lang.NullPointerException error while importing MDL file.Please let me know the solution if any one had experience the same problem in the past
    Thank in advance
    Best Regards
    kumar

    Where there any errors during the import? If so, what were the errors?

Maybe you are looking for

  • Send email from SAP with more than one attachment

    Hi all, How can i send email with more than one attachment and different types of document(doc,pdf,etc.) from SAP to external? Besr regards, Munur

  • Acrobat Crashes when signing a document

    I have Acrobat 8.1.7 professional and all of a sudden I am unable to digitally sign documents. When I attempt to sign a document, the "sign document" dialog box opens, freezes and the acrobat closes down. Can someone assist me with this issue? Window

  • Blotches on the screen

    I have an imac G5 20inch bought 2 months ago, and recently there has been a number of black marks appearing inside the screen. at first I thought it was dead pixels but its definately not. It seems to be appearing on other parts of the screen. Is it

  • Day book,cash book,bank book in sap

    In where we use day book,cash book,bank book in sap can anybody tell me please.. rgs

  • Can't tap or left click on Flex 2 14 periodical​ly

    I have been having trouble with the touchpad on my Flex 2 14 since I bought the machine in December. All of a sudden I will be unable to click or tap the touchpad to get a result. I have to use the touchscreen for the minute or two while this happens