(URGENT) problem with JTable: can't catch ENTER and control focus in JTable

I hava a JTable and a AbstractTableModel.
Here is what i want to DO.
When I press the ENTER or TAB I want to set focus to cell wich is 2 position away from the the sell I am editing
on the same row in the JTable. How can I do this.
in fact, that is my real question HOW to ?
When I press the ENTER or TAB in JTABLE I want to tell to JTable which cell to grab the focus

In the UI is defined the InputMap/ActionMap pair to respond to keys. There is defined an action for ENTER. I have had the same problem, and the only thing that worked for me was to clear the actionMap, and reassign some keys to their original action, and some (e.g. ENTER, TAB) to my actions. This worked. With TAB is harder beacuse i guess it's deeper in the JVM implemented, but after a while i've managed to overwrite that too.

Similar Messages

  • Urgent :problem with JTable on server program

    hi all i am writing an internet cafe timer.there is a table with the following colums:PC Name,IP Address,Status,Time Left, Time Login. ,on the server GUI. Whenever a client connects,a new row having the clients details is added to the table model, which reflects on the table.but if a client disconnects and reconnects, i want it to search thru the rows in the model, if there is a row with its information already,it shouls simply update the status column to "Reconnected", and not add an entirly new row, but if there is no row with its information, it can then add a new row with its information.
    Simply put, when a client connects,it should check
    1)if the table is empty, add a new row;
    2)else, check if tabe already has a row for the client, then update the row,else add a new row.
    its not working this way.it only works for the first client to connect,if other clients connect and disconnect,it still adds a new row, instaed of updating.
    the method doTable() in class ClientThread is what i use .please check it out and help me.
    i have a thread for each client.when a client connects, the server starts the thread and passes an instance of the server ui to the thread, so the threads acess the tablemodel thru this instance.
    Here is a simple run down of my classes
    CafeServer.java
    * @(#)CafeServer.java
    * @author obinna
    * @version 1.00 2007/3/10
    import java.net.*;
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    import java.sql.*;
    public class CafeServer {
         int serverPort;
         int serverLimit;
         //ServerSocket serversocket;
         private static int rownum = -1;
         private static Connection conn;
         private static CafeServerUI serverUI;
    * Creates a new instance of <code>CafeServer</code>.
    public CafeServer() {
         try{
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              conn = DriverManager.getConnection("jdbc:odbc:cafetimer","","");
              System.out.println("connection established with cafetimer database");
         }catch(Exception ex){
              JOptionPane.showMessageDialog(null,"Cannot find database");
              serverUI = new CafeServerUI( this,conn );
    public void closeServer(){
         System.exit(0);
    public static void main(String[] args) throws IOException{
    // TODO code application logic here
    try{
         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
         new CafeServer();
    catch(Exception ex){
         JOptionPane.showMessageDialog(null,"Could Not Find System Look and Feel.\nDefault L&F Loaded.");
         JFrame.setDefaultLookAndFeelDecorated(true);
    ServerSocket serverSocket = null;
    boolean listening = true;
    try {
    serverSocket = new ServerSocket(4444);
    } catch (IOException e) {
    System.err.println("Could not listen on port: 4444.");
    System.exit(-1);
    while (listening)
         new ClientThread(serverSocket.accept(),serverUI,conn).start();
    serverSocket.close();
    CafeServerUI.java
    //import statements.......................................
    public class CafeServerUI extends JFrame{
         public Vector pins = new Vector<String>();
         public DefaultTableModel model;
         public JTable table;
         protected JTextArea msgarea;
         protected JScrollPane scrpane;
         protected JPanel mainp,northp,leftp,rightupp,rightp;
         protected String[] colnames = {"Computer Name","IP Ad
    .............................................................constrctor follows
    ClientThread.java
    import java.io.*;
    import java.net.*;
    import java.sql.*;
    public class ClientThread extends Thread{
         private Socket socket = null;
         private String pin, timeleft, pin3,timeleft3,tleft;
         private CafeServerUI csui = null;
         private Ticket ticket;
         private RemainingTime remtime;
         private String hostname,ipadd;
         private int rownum;
         private Connection conn;
         private Statement stmt;
         private ResultSet rs;
         private boolean found;
         public ObjectOutputStream outputStream;
         public ObjectInputStream inputStream;
         private Admin admin;
         boolean found2 = false;
         //private String[] newrow = new String[5];
    public ClientThread(Socket socket,CafeServerUI csui,Connection conn) {
              super("Client Thread");
              this.socket = socket;
              this.csui = csui;
              this.conn = conn;
              try{
                   stmt = this.conn.createStatement();
              }catch(Exception ex){
                   System.out.println(ex.getMessage() + " : " + ex);
              //this.rownum = rownum;
              hostname = this.socket.getInetAddress().getHostName();
              ipadd = this.socket.getInetAddress().getHostAddress();
              //sString[] newrow = {hostname,ipadd,"Connected","",""};
              doTable();
              //System.out.print("table row " + this.rownum);
              this.csui.oos.addElement(ClientThread.this);
    public void doTable(){
         String[] newrow = {hostname,ipadd,"Connected","",""};
         if(this.csui.model.getRowCount() == 0){
                   this.csui.model.addRow(newrow);
              }else{
                   for(int i=0; i < this.csui.model.getRowCount(); i++ ){
                        String hname = (String)this.csui.model.getValueAt(i,0);
                        if(hname.equalsIgnoreCase(hostname)){
                             this.csui.model.setValueAt("Re Connected",i,2);
                             break;
                        }else{
                             this.csui.model.addRow(newrow);
                             break;
    .....public void run()....

    In the UI is defined the InputMap/ActionMap pair to respond to keys. There is defined an action for ENTER. I have had the same problem, and the only thing that worked for me was to clear the actionMap, and reassign some keys to their original action, and some (e.g. ENTER, TAB) to my actions. This worked. With TAB is harder beacuse i guess it's deeper in the JVM implemented, but after a while i've managed to overwrite that too.

  • Urgent : Problem with Editable  ALV Grid  for Quantity and Currency Fields

    Hi All,
    I am using Editable ALV Grid display and have quantity and value as editable fields in the display.
    When user changes these values these values are not changing properly .
    For the quantity field the domain is MENG13 with 3 deciamal places and here  if we enter 500 it takes it as 0.500   .
    The same problem is for the currency field. Here the Domain is WERT7 with 3 decimal places.
    Here also it takes last 2 digits after decimal places by default.
    Please advice how to get proper values in this case from ALV editable fields.
    Thanks and Regards
    Harshad
    Edited by: Harshad Rahirkar on Dec 25, 2007 7:39 AM

    for all the currency field , it will display like that only.
    u have to manipulate uin program before displaying.
    if they are giving 500, in program multiply with 100 and move it to table.
    when u are getting from table, divinde and display.
    this is what I am doing.
    Reward if helpfull.

  • Urgent: problem with sharing HttpSession  object between Jsp and servlets.

    Hi,
              We are using weblogic 6.0 sp2.
              I m setting a particular object in session in a servlet using
              session.setAttribute() but when i try to retrieve that object using
              session.getAttribute() in a jsp page the value of that object is null. Is
              there any way to configure HttpSession in weblogic so that jsps and servlet
              can share the same session? Or any workaround for this problem.
              Any help in this regard is appreciated.
              Thanks
              -Shree
              

    Just a guess, but it sounds like you have cookies turned off and are not
              using encodeURL. Try enabling cookies and see if that solves the problem.
              Also, it is generally good practice to use encodeURL to protect yourself
              from users who disable session cookies.
              Here's how we use encodeURL in our Servlets:
              gotoPage("/jsp/someJSP.jsp");
              private void gotoPage( String address,
              HttpServletRequest request,
              HttpServletResponse response )
              throws ServletException, IOException
              RequestDispatcher dispatcher =
              etServletContext().getRequestDispatcher( response.encodeURL( address ));
              dispatcher.forward( request, response );
              "Shree Unde" <[email protected]> wrote in message
              news:[email protected]..
              > Hi,
              > We are using weblogic 6.0 sp2.
              > I m setting a particular object in session in a servlet using
              > session.setAttribute() but when i try to retrieve that object using
              > session.getAttribute() in a jsp page the value of that object is null. Is
              > there any way to configure HttpSession in weblogic so that jsps and
              servlet
              > can share the same session? Or any workaround for this problem.
              > Any help in this regard is appreciated.
              > Thanks
              > -Shree
              >
              >
              

  • Selection Problem with JTable

    Hello,
    i have a selection problem with JTable. I want to allow only single cell selection and additionally limit the selection to the first column.
    I preffered the style from MS Outlook Express where you can select the email accounts to edit.
    It is a table like this:
    Account name  |   Type  |   ...
    --------------|---------|---------------------
    Hotmail       |   POP3  |
    GMX           |   IMAP  |The selection should be only avaibable at 'Hotmail' or 'GMX' - not at 'POP3', 'IMAP' or as complete row selection.
    Please help me!
    Thanks.
    Warlock

    Maybe this will helpimport java.awt.*;
    import javax.swing.*;
    public class Test3 extends JFrame {
      public Test3() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        String[] head = {"One", "Two"};
        String[][] data = {{"R1-C1", "R1-C2"}, {"R2-C1", "R2-C2"}};
        JTable jt = new JTable(data, head);
        jt.getColumnModel().setSelectionModel(new MyTableSelectionModel());
        content.add(new JScrollPane(jt), BorderLayout.CENTER);
        jt.setCellSelectionEnabled(true);
        jt.setRowSelectionAllowed(false);
        jt.setColumnSelectionAllowed(false);
        setSize(300, 300);
        setVisible(true);
      public static void main(String[] arghs) { new Test3(); }
    class MyTableSelectionModel extends DefaultListSelectionModel {
      public void setSelectionInterval(int index0, int index1) {
        super.setSelectionInterval(0, 0);
    }

  • TS3899 With Yahoo Mail, and anotare account (Inacap Mail), I can only receive mails but I can't send emails. I don't know if this is a problem of the iPad or it is a problem with yahoo mail, because using Gmail and the email of my job I don' have this pro

    With Yahoo Mail, and anotare account (Inacap Mail), I can only receive mails but I can't send emails. I don't know if this is a problem of the iPad or it is a problem with yahoo mail, because using Gmail and the email of my job I don' have this problem.

    Google them to confirm the settings that you need for the outgoing server, then check the setting you entered on the pad.  Pay real close attention to the outgoing server name, and port.  You may need to change in on the pad. 

  • URGENT Problem with Greek Character from an Oracle database

    Hello, I am having a serious and urgent problem with the character settings of an oracle database (8.1.7). The database is sitting in a solaris unix server and when we run the env command we have the following in the NLS_LANG parameter: AMERICAN_AMERICA.WE8ISO8859P1 (I do not know if this is helpful). When I retrieve data from oracle database (through a VB.NET 2005 program)to a dataset I use a special font in order to see the greek characters (HELLASARIAL). But when I am trying to save these data to a TXT file the greek characters are like Chinese to us. I tried several encodings (System.Text.Encoding.GetEncoding(869)) but without success. Can someone tell me how to convert the oracle greek characters during the selection or during the saving to the TXT file?
    Please respond as fast as you can.
    Thanks in advance

    Here is the answer of the microsoft:
    I have the information that you have a VB.Net 2005 application connected to an Oracle database 8.1.7.4 hosted on a UNIX server.
    This database has the CharacterSet WE8ISO8859P1.
    When retrieving Greek characters from this database in the application, you cannot see them.
    Could you please send me a screenshot of these characters in the .Net application?
    Are they displayed as gibberish, or as inverted questions marks (?)?
    I already had similar cases with Hebrew characters hosted on an Oracle database.
    These characters were displayed as questions marks on the client side.
    This is due to the fact that System.Data.OracleClient is using the Server CharacterSet to display the characters.
    If your Greek characters are not stored in the WE8ISO8859P1 characterset, then they won’t display correctly on the client-side.
    This is different from OLEDB where you could interact on client side by modifying the NLS_LANG parameter in the registry HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOME0.
    The client NLS_LANG and the server CharacterSet had to match in order to correctly display the data, and avoid SQL*NET conversion.
    So there are two solutions to your case:
    - The first one is to create a new database using the P8 characterset. The Oracle .Net managed provider will so be able to use it and display the characters correctly.
    - The second one is to use the OLEDB.Net managed provider, and then use OLEDB for Oracle provider. OLEDB will take care of the client NLS_LANG registry parameter.
    Would it be possible to test your application against an Oracle database with WE8ISO8859P8 characterset?
    Would it be possible to test it with the OLEDB .Net managed provider, and after checking the NLS_LANG client registry parameter?

  • Another problem with JTable

    Hi,
    I have encountered a problem with JTable, i am trying to display some 15 columns and their values , one of the columns value is null, then the JTable is not displaying its value from this column(which is with null value) onwards.
    Can anybody assiss me in this matter.
    Regards
    khiz_eng

    I don't know If I can fix your problem, but
    I know just that it works on my PC.... It's very very
    slow... I don't know how to insert PageSetUp option... I have to study the problem.....
    However I don't think it's a hard problem....
    I want ask to you if you have found some problems when you are in Editing mode in a cell.....
    in the jdk1.2 version I could save while was in editing mode using the editingStopped method.
    It permit to update all data .... also the data in the cell I was editing.
    in the jdk 1.3 if I use this method It doesn't work properly... It maybe destroy the content object in the Cell..... because I'm able to print all the table except the editing cell (it throw an exception...)
    What's changed????
    I don't know...
    Can u help me?

  • TS3694 good evening i have an problem with my iphone 4 the wif and network cant on now if i tray is showing iTunes i tray to reload the ios is showing an error -1 can you help me

    good evening i have an problem with my iphone 4 the wif and network cant on now if i tray is showing iTunes i tray to reload the ios is showing an error -1 can you help me

    No problem, glad to help!
    Update: my PC USB hub was connected to a USB 3 port, I connected the 30 pin cable directly to my PC, And the restore worked just fine. Restored phone from iCloud backup and seems to be working fine.

  • Hi I've a big problem with adobe acrobat reader XI pro and I hope you can help me. The problem is; when I past copied text from some pdf books (not all of them) it past symbols only! wherever I past it! and even if I coped that text from another pdf reade

    Hi
    I've a big problem with adobe acrobat reader XI pro and I hope you can help me.
    The problem is; when I past copied text from some pdf books (not all of them) it past symbols only! wherever I past it! and even if I coped that text from another pdf reader (adobe pdf reader, internet browsers, ...etc.).
    This problem started to happen since yesterday when I installed adobe acrobat reader XI pro to try it before I buy it, and before that when I was using the free adobe pdf reader I was totally able to copy any text from any pdf and past it anywhere with nothing wrong.
    What can I do?
    thank you a lot.

    There is no product called Adobe Acrobat Reader Pro. There is
    - Adobe Acrobat Pro ($$)
    - Adobe Reader (free)
    Which do you have? And are you a programmer?

  • I have just purchased elements 12. It will not convert a raw file for me. i have downloaded DNG convertor 8.5 but it says that my Canon 70d is not compatible. I never had a problem with my last camera canon 7d and elments 8. Can someone help me please..

    i have just purchased elements 12. It will not convert a raw file for me. i have downloaded DNG convertor 8.5 but it says that my Canon 70d is not compatible. I never had a problem with my last camera canon 7d and elments 8. Can someone help me please

    Did you buy PSE in the mac app store? If not, just go to Help>Updates in the editor and update camera raw and you should be able to open the raw files in PSE 12 directly without the DNG converter.

  • URGENT : problem with CIOUE_ELEMENT_TYPE

    On installing the repository from the NT client (repo adm utility), it goes well for table, views....till packages and hangs at the package CIOUE_ELEMENT_TYPE for hours together. The DBMS seems to be unable to compile the package body CIOUE_ELEMENT_TYPE.
    The DBMS is 8.1.7 Enterprise Edition
    The client is Designer 6i Product 6.5.90.0.11 and Oracle Repository 6i Product 6.5.0.14
    I know that this question has already been asked, but I could not find the solution and the correct and full reply to it.
    All comments are welcome. Please give me a reply !!
    Thanks you.
    Said ASSAR - I.N.T France
    [email protected]

    Hello,
    We were made aware of one or two problems with the
    installation of this object and I believe they were
    fixed in Designer 6i Release 2 and 9i.
    The Designer 6i client version you give is for Release
    4.5, the latest available, so that should be OK.
    However, the Repository 6i version number you give does
    not seem to match. If you install the repository using
    the Designer6i 6.5.90.0.11 client, it should install
    without any problem.
    Where is the Repository 6i 6.5.0.14 from? Please can
    you give me more details?
    Regards,
    Dominic
    Designer Product Management

  • Lately and i dont know why i see a pop up about a problem with script. can some1 help me?

    there is a pop up about a problem with script. it ask me end and contuniue the script. i didnt have that problem before. plz help me it gets really irritating. it asks a lot

    This issue can be caused by an extension that isn't working properly.
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.com/kb/Safe+Mode

  • A problem with JTable

    Hi !
    I have a problem with JTable - would like to use this component as a simple list of rows taken from a database : don't want to be able select or set a focus to a column - want only to be able select and set focus to a row ( just like in the menus). How to disable "focusability" for a cell with JTable ? Could You help me ?
    thnx in advance

    The Border is changed by the renderer, depending on whether the cell has focus or not. So you will need to create custom renderers without a Border. Something like:
    class NoBorderRenderer extends DefaultTableCellRenderer
         public Component getTableCellRendererComponent(
              JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
              super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
              setBorder(null);
              return this;
    }

  • Problem With ButtonUI in an Auxiliary Look and Feel

    This is my first post to one of these forums, so I hope everything works correctly.
    I have been trying to get an axiliary look and feel installed to do some minor tweaking to the default UI. In particular, I need it to work with Windows and/or Metal as the default UI. For the most part I let the installed default look and feel handle things with my code making some colors lighter, darker, etc. I also play with focus issues by adding FocusListeners to some components. I expect my code to work reasonably well no matter what the default look and feel is. It works well with Motif, Metal, and Windows, the only default look and feels I've tested with. What I'm going to post is a stripped down version of what I have been working on. This example makes gross changes to the JButton background and foreground colors in order to illustrate what I've encountered.
    I have three source code files. The first, Problem.java, creates a JFrame and adds five buttons to it. One button installs MyAuxLookAndFeel as an auxiliary look and feel using MyAuxButtonUI for the look and feel of JButtons. The next button removes that look and feel. The next button does nothing except print a line to System.out. The next button installs MyAuxLookAndFeel as an auxiliary look and feel using MyModButtonUI for the look and feel of JButtons. The last button removes that look and feel.
    The problem is, when I install the first auxiliary look and feel, buttons are no longer tabable. Also, they cannot be invoked by pressing the space button when they're in focus. When I remove the first auxiliary look and feel everything reverts to behaving normally. When I add the "Mod" version, button tabability is fine. The only difference is I've added the following code:
    if ( c.isFocusable() ) {
       c.setFocusable(true);
    }That strikes me as an odd piece of code to profoundly change the program behavior. Anyway, after adding and removing the "Mod" look and feel, the tababilty is forever fixed. That is, if I subsequently re-install the first look and feel, tababilty works just fine.
    The problem with using the space bar to select a focused button is more problematic. My class is not supposed to mess with the default look and feel which may or may not use the space bar to press the button with focus. When the commented code in MyModButtonUI is uncommented, things behave correctly. Even the statement
    button.getInputMap().remove( spaceKeyStroke );doesn't mess things up after the auxiliary look and feel is removed. So far I've tested this with JRE 1.4.2_06 under Windows 2000, JRE 1.4.2_10 under Windows XP, and JRE 1.5.0_06 under Windows XP and the behavior is the same.
    All of this leads me to two questions.
    1. Is my approach fundamentally flawed? I've extended TextUI and ScrollBarUI with no problems. This is the only problem I've encountered with ButtonUI. My real workaround for the space bar issue is better than the one I've supplied in the example, but it certainly is not guaranteed to work for any arbitrary default look and feel.
    2. Assuming I have no fundamental problems with my approach, it's possible I've found a real bug. I searched the bug database and couldn't find anything like this. Of course, this is the first time I've tried seasrching the database for a bug so my I'm doing it badly. Has this already been reported as a bug? Is there any reason I shouldn't report it?
    What follows is the source code for my example. It's in three files because the two ButtonUI classes must be public in order to work. Thanks for insight you can provide.
    Bill
    File Problem.java:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Problem extends JFrame {
       public boolean isAuxInstalled = false;
       public boolean isModInstalled = false;
       public LookAndFeel lookAndFeel = new MyAuxLookAndFeel();
       private static int ctr = 0;
       public static void main( String[] args ) {
          new Problem();
       public Problem() {
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setSize(250, 150);
          setTitle("Button Test");
          JButton install = new JButton("Install");
          JButton remove = new JButton("Remove");
          JButton doNothing = new JButton("Do Nothing");
          JButton installMod = new JButton("Install Mod");
          JButton removeMod = new JButton("Remove Mod");
          this.getContentPane().setLayout(new FlowLayout());
          this.getContentPane().add(install);
          this.getContentPane().add(remove);
          this.getContentPane().add(doNothing);
          this.getContentPane().add(installMod);
          this.getContentPane().add(removeMod);
          install.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( !isAuxInstalled ) {
                   isAuxInstalled = true;
                   UIManager.addAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          remove.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( isAuxInstalled ) {
                   isAuxInstalled = false;
                   UIManager.removeAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          doNothing.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                System.out.println( "Do nothing " + (++ctr) );
          installMod.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( !isModInstalled ) {
                   isModInstalled = true;
                   UIManager.addAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          removeMod.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( isModInstalled ) {
                   isModInstalled = false;
                   UIManager.removeAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          setVisible(true);
       class MyAuxLookAndFeel extends LookAndFeel {
          public String getName() {
             return "Button Test";
          public String getID() {
             return "Not well known";
          public String getDescription() {
             return "Button Test Look and Feel";
          public boolean isSupportedLookAndFeel() {
             return true;
          public boolean isNativeLookAndFeel() {
             return false;
          public UIDefaults getDefaults() {
             UIDefaults table = new MyDefaults();
             Object[] uiDefaults = {
                "ButtonUI", (isModInstalled ? "MyModButtonUI" : "MyAuxButtonUI"),
             table.putDefaults(uiDefaults);
             return table;
       class MyDefaults extends UIDefaults {
          protected void getUIError(String msg) {
    //         System.err.println("(Not) An annoying error message!");
    }File MyAuxButtonUI.java:
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.plaf.*;
    import javax.swing.plaf.multi.*;
    import javax.accessibility.*;
    public class MyAuxButtonUI extends ButtonUI {
       private Color background;
       private Color foreground;
       private ButtonUI ui = null;
       public static ComponentUI createUI( JComponent c ) {
          return new MyAuxButtonUI();
       public void installUI(JComponent c) {
          MultiButtonUI multiButtonUI = (MultiButtonUI) UIManager.getUI(c);
          this.ui = (ButtonUI) (multiButtonUI.getUIs()[0]);
          super.installUI( c );
          background = c.getBackground();
          foreground = c.getForeground();
          c.setBackground(Color.GREEN);
          c.setForeground(Color.RED);
       public void uninstallUI(JComponent c) {
          super.uninstallUI( c );
          c.setBackground(background);
          c.setForeground(foreground);
          this.ui = null;
       public void paint(Graphics g, JComponent c) {
          this.ui.paint( g, c );
       public void update(Graphics g, JComponent c) {
          this.ui.update( g, c );
       public Dimension getPreferredSize(JComponent c) {
          if ( this.ui == null ) {
             return super.getPreferredSize( c );
          return this.ui.getPreferredSize( c );
       public Dimension getMinimumSize(JComponent c) {
          if ( this.ui == null ) {
             return super.getMinimumSize( c );
          return this.ui.getMinimumSize( c );
       public Dimension getMaximumSize(JComponent c) {
          if ( this.ui == null ) {
             return super.getMaximumSize( c );
          return this.ui.getMaximumSize( c );
       public boolean contains(JComponent c, int x, int y) {
          if ( this.ui == null ) {
             return super.contains( c, x, y );
          return this.ui.contains( c, x, y );
       public int getAccessibleChildrenCount(JComponent c) {
          if ( this.ui == null ) {
             return super.getAccessibleChildrenCount( c );
          return this.ui.getAccessibleChildrenCount( c );
       public Accessible getAccessibleChild(JComponent c, int ii) {
          if ( this.ui == null ) {
             return super.getAccessibleChild( c, ii );
          return this.ui.getAccessibleChild( c, ii );
    }File MyModButtonUI.java:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.plaf.*;
    public class MyModButtonUI extends MyAuxButtonUI
       static KeyStroke spaceKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0 );
       public static ComponentUI createUI( JComponent c ) {
          return new MyModButtonUI();
       public void installUI(JComponent c) {
          super.installUI(c);
          c.setBackground(Color.CYAN);
          if ( c.isFocusable() ) {
             c.setFocusable(true);
    //      final JButton button = (JButton) c;
    //      button.getInputMap().put( spaceKeyStroke, "buttonexample.pressed" );
    //      button.getActionMap().put( "buttonexample.pressed", new AbstractAction() {
    //         public void actionPerformed(ActionEvent e) {
    //            button.doClick();
    //   public void uninstallUI(JComponent c) {
    //      super.uninstallUI(c);
    //      JButton button = (JButton) c;
    //      button.getInputMap().remove( spaceKeyStroke );
    //      button.getActionMap().remove( "buttonexample.pressed" );
    }

    here is the code used to change the current look and feel :
    try {
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
             catch (InstantiationException e)
                  System.out.println("Error occured  "+ e.toString());
             catch (ClassNotFoundException e)
                  System.out.println("Error occured  "+ e.toString());
             catch (UnsupportedLookAndFeelException e)
                  System.out.println("Error occured  "+ e.toString());
             catch (IllegalAccessException e)
                  System.out.println("Error occured in .. " + e.toString());
             Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
             Fenetre fen = new Fenetre();
             fen.setSize(dim.width, dim.height);
             fen.setResizable(false);
                 fen.setLocation(0, 0);
                  fen.setVisible(true);

Maybe you are looking for

  • Check for required fields before locking subforms and submitting

    Hello, I have a 5-page form with many questions, to be completed by the original requestor and multiple approvers.  What I'm trying to do is have the original requestor's Submit button on p. 3 lock the input on the first three pages, but first check

  • Is it time to upgrade from CS3 to CS4?

    I currently use CS3 but have a version of CS4.  I edit full HD XD CAM EX and Cineform 25p.   The reason I have not yet switched to CS4 is because I am waiting for the bugs to be worked out.  I am now checking in to see how things have moved forward o

  • Multiple devices - 1 Apple ID, time for another ID?

    Hi As a family we currently only use 1 Apple ID - this is the ID on the computer that has Itunes on, any icloud stuff and then we use it on 4 devices belonging to each of us. This was I can keep track of what the children are doing plus we share all

  • Why can't you create image hyperlinks in Yahoo mail??!!

    ''locking - duplicate - https://support.mozilla.com/en-US/questions/806494'' The whole feature that allows images to be entered inline with text is messed up when using Firefox. And you can't make any image a hyperlink! This is a really useful featur

  • Codebase for jnlp

    Is it possible to give codebase for jnlp at runtime.Because in our app. codebase is not known ahead of time. So, can we use any property file for setting codebase? Thanks for any help!!!