WindowsLookAndFeel problem

I'm running into a problem when I set the WindowsLookAndFeel as the default "skin".
Basically, I get dots under text for menus, tooltext, etc. This isn't something crucial obviously, it just looks dumb. To get an idea what I mean, visit:
http://www.tecnogize.com/guiprob.gif
(image of a tooltip with the problem)
See the dots under the o's and t for example in the yellow tooltip? That's what I'm talking about, and this is in the menus and other components as well.
Any of you ever ran into this? Know a way to fix it?
Thanks, Jens

I thought UIDefaults was used to store those kind of properties. Access to the UIDefaults is provided by the UIManager class. Use UIDefaults.put( Object, Object ) to set the font.
question: how do I know which property is the one I seek?
answer: Well, dump your UIDefaults instance into a file, search that file to see if it contains a key like "TextArea.font", if yes, use it to setup your font. If not, well, shit happens :) Note that you only have to dump the file once. After just recompile your code with the found property name defined a a constant or even hard coded.
I know this is a very empiric solution, but the property names do not seemed to be documented. They might even differs from one LookAndFeel to one another.

Similar Messages

  • WindowsLookAndFeel on Linux : BIG  and complete PROBLEM

    Hello,
    I have implemented a GUI application with the windows look and feel. I work under Linux with the jdk 1.3 and eclipse.
    To run my application with the windows lf, I add the following lines in my code :
    System.setProperty("os.name","Not Windows");
    try {
         UIManager.setLookAndFeel(new WindowsLookAndFeel());
    } catch (Exception e) {
              e.printStackTrace();
              SwingUtilities.updateComponentTreeUI(getRootPane());
    In Eclipse, it works well, but an execution from the line command in a Xterm generate the following exception :
    java.lang.NumberFormatException: multiple points
         at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1073)
         at java.lang.Float.valueOf(Float.java:186)
         at com.sun.java.swing.plaf.windows.WindowsLookAndFeel.initialize(WindowsLookAndFeel.java:108)
    It seems that the problem is caused by the following line :
    System.getProperty("os.name","Not Window");
    the system property os.name is parsed as a float.
    what can I do to run my application with the windows lf and under linux ?
    any help will be helpful
    Regards,
    Anne

    In Eclipse, it works well, but an execution from the
    line command in a Xterm generate the following
    exception :
    java.lang.NumberFormatException: multiple points
    at
    java.lang.FloatingDecimal.readJavaFormatString(Floatin
    Decimal.java:1073)
         at java.lang.Float.valueOf(Float.java:186)
    at
    com.sun.java.swing.plaf.windows.WindowsLookAndFeel.ini
    ialize(WindowsLookAndFeel.java:108)Make sure that Eclipse is using the JDK matching the JRE you use to run the program (Windows/Preferences/Java/installed JREs or somesuch)
    It seems that the problem is caused by the following
    line :
    System.getProperty("os.name","Not Window");
    the system property os.name is parsed as a float.Using an official System property is shooting yourself in the foot. You can't tell what else on in the Java runtime has a depency on it. You can set your own property
    for this (System.setProperty("MyFalseOpsSys","Not Windows")). I wonder what use you have for it since you force the Windows L&F anyway?
    >
    what can I do to run my application with the windows
    lf and under linux ?
    any help will be helpful Maybe find a JRE which supports it natively. Or, if you are very lucky, extract the relevant classes and resources from the JAR of a Windows JRE (in Sun's rt.jar, com/sun/java/swing/plaf/windows/) and put them into some independent JAR you add to your Linux classpath. For better luck, use the very same version for both JRE. Pray that there are no native methods involved.

  • WindowsLookAndFeel on Linux : BIG PROBLEM

    Hello,
    I have implemented a GUI application with the windows look and feel. I work under Linux with the jdk 1.3 and eclipse.
    To run my application with the windows lf, I add the following lines in my code :
    System.setProperty("os.name","Not Windows");
    try {
         UIManager.setLookAndFeel(new WindowsLookAndFeel());
    } catch (Exception e) {
              e.printStackTrace();
              SwingUtilities.updateComponentTreeUI(getRootPane());

    Availability of specific L&F is platform dependent. On a given Platform, you usually have the choice between the local one or the standard Java one (aka "Metal").
    Forcing innocent Linux users to use a Windows L&F would not do much good to the popularity of your software anyway :-) "Look" isn't everything, the "Feel" part is important too (default keys, some window behavior), and your app you remain consistent with the rest of the Linux desktop.

  • Background picture n problem on display other JInternal frame

    beginer;
    this is my code below n i compile it n the picture display correctly, but it seems to hide other internal frame as well, what wrong with my code :(, the problem is been specified between ? symbols
    public class InternalFrameDemo extends JFrame implements ActionListener {
    JDesktopPane desktop;
    public InternalFrameDemo() {
    super("InternalFrameDemo");
    int inset = 50;
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(inset, inset,
    screenSize.width - inset*2,
    screenSize.height - inset*2);
    Toolkit kit = Toolkit.getDefaultToolkit();
    Image icon = kit.getImage("ADD.gif");
    setIconImage(icon);
    //Set up the GUI.
    desktop = new JDesktopPane(); //a specialized layered pane
    createFrame(); //create first "window"
    setContentPane(desktop);
    setJMenuBar(createMenuBar());
    //Make dragging a little faster but perhaps uglier.
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    ImageIcon image = new ImageIcon("abc.jpg");
    JLabel background = new JLabel(image);
    background.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
    getLayeredPane().add(background, new Integer(Integer.MIN_VALUE) );
    JPanel panel = new JPanel();
    panel.setOpaque(false);
    setContentPane( panel );
    protected JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    //Set up the menu item
    return menuBar;
    public void actionPerformed(ActionEvent e) {
    else {
    quit();
    protected void createFrame() {
    Books frame = new Books();
    frame.setVisible(true);
    desktop.add(frame);
    try {
    frame.setSelected(true);
    catch (java.beans.PropertyVetoException e) {}
    protected void quit() {
    System.exit(0);
    public static void main(String[] args) {
    try {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    catch (Exception e) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    InternalFrameDemo frame = new InternalFrameDemo();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Display the window.
    frame.setVisible(true);
    tanz.

    This might be what you are trying to do:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.plaf.*;
    public class TestInternalFrame extends JFrame
         ImageIcon icon;
         public TestInternalFrame()
              icon = new ImageIcon("????.jpg");
              JDesktopPane desktop = new JDesktopPane()
                 public void paintComponent(Graphics g)
                      Dimension d = getSize();
                      g.drawImage(icon.getImage(), 0, 0, d.width, d.height, null);
              getContentPane().add( desktop );
              final JInternalFrame internal =
                   new JInternalFrame( "Internal Frame", true, true, true, true );
              desktop.add( internal );
              internal.setLocation( 50, 50 );
              internal.setSize( 300, 300 );
              internal.setVisible( true );
         public static void main(String args[])
              TestInternalFrame frame = new TestInternalFrame();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.setSize(400, 400);
              frame.setVisible(true);
    }

  • Problem with JFrame and JPanel

    Okay, well I'm busy doing a lodge management program for a project and I have programmed this JFrame
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class FinalTest extends JFrame
         public JPanel contentPane;
         public JImagePanel imgPanel;
         private JLabel[] cottageIcon;
         private boolean keepMoving;
         private int selectedCottage;
         public FinalTest()
              super();
              initializeComponent();
              addActionListeners();
              this.setVisible(true);
         private void initializeComponent()
              contentPane = (JPanel)getContentPane();
              contentPane.setLayout(null);
              imgPanel = new JImagePanel("back.png");
               imgPanel.setLayout(null);
              imgPanel.setBackground(new Color(1, 0, 0));
                   addComponent(contentPane, imgPanel, 10,10,imgPanel.getImageWidth(),imgPanel.getImageHeight());
              cottageIcon = new JLabel[6];
              keepMoving = true;
              selectedCottage = 0;
              cottageIcon[0] =  new JLabel();
              //This component will never be added or shown, but needs to be there to cover for no cottage selected
              for(int a = 1; a < cottageIcon.length; a++)
                   cottageIcon[a] = new JLabel("C" + (a));
                   cottageIcon[a].setBackground(new Color(255, 0, 0));
                    cottageIcon[a].setHorizontalAlignment(SwingConstants.CENTER);
                    cottageIcon[a].setHorizontalTextPosition(SwingConstants.LEADING);
                    cottageIcon[a].setForeground(new Color(255, 255, 255));
                    cottageIcon[a].setOpaque(true);
                    addComponent(imgPanel,cottageIcon[a],12,(a-1)*35 + 12,30,30);
                this.setTitle("Cottage Chooser");
                this.setLocationRelativeTo(null);
              this.setSize(new Dimension(540, 430));
         private void addActionListeners()
              imgPanel.addMouseListener(new MouseAdapter()
                   public void mousePressed(MouseEvent e)
                        imgPanel_mousePressed(e);
                   public void mouseReleased(MouseEvent e)
                        imgPanel_mouseReleased(e);
                   public void mouseEntered(MouseEvent e)
                        imgPanel_mouseEntered(e);
              imgPanel.addMouseMotionListener(new MouseMotionAdapter()
                   public void mouseDragged(MouseEvent e)
                        imgPanel_mouseDragged(e);
         private void addComponent(Container container,Component c,int x,int y,int width,int height)
              c.setBounds(x,y,width,height);
              container.add(c);
         private void imgPanel_mousePressed(MouseEvent e)
              for(int a = 1; a < cottageIcon.length; a++)
                   if(withinBounds(e.getX(),e.getY(),cottageIcon[a].getBounds()))
                        System.out.println("B" + withinBounds(e.getX(),e.getY(),cottageIcon[a].getBounds()));
                        selectedCottage = a;
                        keepMoving = true;
         private void imgPanel_mouseReleased(MouseEvent e)
              System.out.println("called");
              selectedCottage = 0;
              keepMoving = false;
         private void imgPanel_mouseDragged(MouseEvent e)
               System.out.println("XXX" + Math.random() * 100);
              if(keepMoving)
                   int x = e.getX();
                    int y = e.getY();
                    if(selectedCottage!= 0)
                         cottageIcon[selectedCottage].setBounds(x-(30/2),y-(30/2),30,30);
                    if(!legalBounds(imgPanel,cottageIcon[selectedCottage]))
                        keepMoving = false;
                        cottageIcon[selectedCottage].setBounds(imgPanel.getWidth()/2,imgPanel.getHeight()/2,30,30);
              System.out.println(cottageIcon[selectedCottage].getBounds());
         private void imgPanel_mouseEntered(MouseEvent e)
               System.out.println("entered");
         private void but1_actionPerformed(ActionEvent e)
              String input = JOptionPane.showInputDialog(null,"Enter selected cottage");
              selectedCottage = Integer.parseInt(input) - 1;
         public boolean legalBounds(Component containerComponent, Component subComponent)
              int contWidth = containerComponent.getWidth();
              int contHeight = containerComponent.getHeight();
              int subComponentX = subComponent.getX();
              int subComponentY = subComponent.getY();
              int subComponentWidth = subComponent.getWidth();
              int subComponentHeight = subComponent.getHeight();
              if((subComponentX < 0) || (subComponentY < 0) || (subComponentX > contWidth) || (subComponentY > contHeight))
                   return false;
              return true;
         public boolean withinBounds(int mouseX, int mouseY, Rectangle componentRectangle)
              int componentX = (int)componentRectangle.getX();
              int componentY = (int)componentRectangle.getY();
              int componentHeight = (int)componentRectangle.getHeight();
              int componentWidth = (int)componentRectangle.getWidth();
              if((mouseX >= componentX) && (mouseX <= (componentX + componentWidth)) && (mouseY >= componentY) && (mouseY <= (componentY + componentWidth)))
                   return true;
              return false;
         public static void main(String[] args)
              JFrame.setDefaultLookAndFeelDecorated(true);
              //JDialog.setDefaultLookAndFeelDecorated(true);
              try
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              catch (Exception ex)
                   System.out.println("Failed loading L&F: ");
                   System.out.println(ex);
              FinalTest ft = new FinalTest();
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class JImagePanel extends JPanel
      private Image image;
      public JImagePanel(String imgFileName)
           image = new ImageIcon(imgFileName).getImage();
        setLayout(null);
      public void paintComponent(Graphics g)
        g.drawImage(image, 0, 0, null);
      public Dimension getImageSize()
                Dimension size = new Dimension(image.getWidth(null), image.getHeight(null));
             return size;
      public int getImageWidth()
                int width = image.getWidth(null);
                return width;
      public int getImageHeight()
              int height = image.getHeight(null);
              return height;
    }Now the problem I'm having is changing that class to a JFrame, it seems simple but I keep having problems like when it runs from another JFrame nothing pops up. I can do it like this:
    FinalTest ft = new FinalTest();
    ft.setVisible(false);
    JPanel example = ft.contentPanehowever I will probably be marked down on this for bad code. I'm not asking for the work to be done for me, but I'm really stuck on this and just need some pointers so I can carry on with the project. Thanks,
    Steve

    CeciNEstPasUnProgrammeur wrote:
    I'd actually consider your GUI being a JPanel instead of a JFrame quite good design - makes it easy to put the stuff into an applet when necessary...
    Anyway, you should set setVisible() to true to make it appear, not to false. Otherwise, I don't seem to understand your problem.That is actually my problem. I am trying to convert this JFrame to a JPanel

  • Problem with writing and reading using serialization

    I am having a problem with writing and reading an object that has another object in it. The purpose of the class is to write a order that has multiple items in it. And there will be several orders. This is for an IB project, where one of the requirements is to utilize a hierarchical composite data structure. That is, it is "one that contains more than one element and at least one of the elements is a composite data structure. Examples are, an array or linked list of records, a record that has one field that is another record, or an array". The code is shown below:
    The error produced is
    java.lang.NullPointerException
         at SamsonRubberIndustries.CustomerOrderDetails.createCustOrdDetailsScreen(CustomerOrderDetails.java:150)
         at SamsonRubberIndustries.CustomerOrderDetails$1.run(CustomerOrderDetails.java:78)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    public class CustOrdObject implements Serializable {
         public int CustID;
         public int CustOrderID;
         public Object OrderDate;
         public InnerCustOrdObject[] innerCustOrdObj;
         public float GrandTotal;
         public int MaxItems;
         public CustOrdObject() {}
         public CustOrdObject(InnerCustOrdObject[] innerCustOrdObj,
    int CustID, int CustOrderID, Object OrderDate,
    float GrandTotal, int innerarrlength, int innerarrpos, int MaxItems) {
              this.CustID = CustID;
              this.CustOrderID = CustOrderID;
              this.OrderDate = OrderDate;
              this.GrandTotal = GrandTotal;          
              this.MaxItems = MaxItems;
              this.innerCustOrdObj = new InnerCustOrdObject[MaxItems];
         public InnerCustOrdObject[] getInnerCustOrdObj() {
              return innerCustOrdObj;
         public void setInnerCustOrdObj(InnerCustOrdObject[] innerCustOrdObj) {
              this.innerCustOrdObj = innerCustOrdObj;
         public int getCustID() {
              return CustID;
         public void setCustID(int custID) {
              CustID = custID;
         public int getCustOrderID() {
              return CustOrderID;
         public void setCustOrderID(int custOrderID) {
              CustOrderID = custOrderID;
         public Object getOrderDate() {
              return OrderDate;
         public void setOrderDate(Object orderDate) {
              OrderDate = orderDate;
         public void setGrandTotal(float grandTotal) {
              GrandTotal = grandTotal;
         public float getGrandTotal() {
              return GrandTotal;
         public int getMaxItems() {
              return MaxItems;
         public void setMaxItems(int maxItems) {
              MaxItems = maxItems;
    public class InnerCustOrdObject implements Serializable{
         public int ItemNumber;
         public float UnitPrice;
         public int QuantityRequired;
         public float TotalPrice;
         public InnerCustOrdObject() {}
         public InnerCustOrdObject(int ItemNumber, float
    UnitPrice, int QuantityRequired, float TotalPrice){
              this.ItemNumber = ItemNumber;
              this.UnitPrice = UnitPrice;
              this.QuantityRequired = QuantityRequired;
              this.TotalPrice = TotalPrice;
         public int getItemNumber() {
              return ItemNumber;
         public void setItemNumber(int itemNumber) {
              ItemNumber = itemNumber;
         public int getQuantityRequired() {
              return QuantityRequired;
         public void setQuantityRequired(int quantityRequired) {
              QuantityRequired = quantityRequired;
         public float getTotalPrice() {
              return TotalPrice;
         public void setTotalPrice(float totalPrice) {
              TotalPrice = totalPrice;
         public float getUnitPrice() {
              return UnitPrice;
         public void setUnitPrice(float unitPrice) {
              UnitPrice = unitPrice;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import javax.swing.*;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.DefaultTableModel;
    public class CustomerOrderDetails extends CommonFeatures{
         //TODO
         private static int MAX_ORDERS = 200;
         private static int MAX_ORDERITEMS = 100;
         private static int MaxRecord;
         private static int CurrentRecord = 1;
         private static int currentItem;
         private static int MaxItems;
         private static boolean FileExists, recFileExists;
         private static CustOrdObject[] orderDetails = new CustOrdObject[MAX_ORDERS];
         private static InnerCustOrdObject[] innerCustOrdObj = new InnerCustOrdObject[MAX_ORDERITEMS];     
         private static File OrderDetailsFile = new File("CustOrdDetails.dat");
         private static File OrdRecordNumStore = new File("OrdRecordNumStore.txt");
         private static PrintWriter writeFile;
         private static BufferedReader readFile;
         private static ObjectOutputStream objOut;
         private static ObjectInputStream objIn;
         //Set format for date
         SimpleDateFormat simpleDF = new SimpleDateFormat("dd MM yyyy");
         //--<BEGINNING>--Declaring Interface Variables------------------------------------------//
         private JPanel innertoppanel, innercenterpanel, innerbottompanel, innerrightpanel, innerleftpanel;
         private JLabel CustIDLbl, CustOrderIDLbl, OrderedDateLbl, GrandTotLbl, ItemNumberLbl,UnitPriceLbl, QuantityReqLbl, TotPriceLbl;
         private JTextField CustIDTxt, CustOrderIDTxt, OrderedDateTxt, GrandTotTxt, ItemNumberTxt, UnitPriceTxt, QuantityReqTxt, TotPriceTxt;
         private JButton addrecordbtn, savebtn, externalprevbtn, externalnextbtn, internalprevbtn, internalnextbtn, gotorecordbtn, additemreqbtn;
         //--<END>--Declaring Interface Variables------------------------------------------------//
         public static void main(String[] args) {
              final CustomerOrderDetails COD = new CustomerOrderDetails();
              java.awt.EventQueue.invokeLater(new Runnable() {
                   public void run() {
                        try {
                             UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                             COD.createCustOrdDetailsScreen();
                        } catch (Exception eb) {
                             eb.printStackTrace();
         //--<BEGINNING>--Creating CustomerOrderDetails Screen---------------------------------------//
         public JFrame createCustOrdDetailsScreen() {
              createDefaultFrame();
              mainframe.setSize(800,500);
              createContainerPanel();
              containerpanel.add(createCustOrdDetailsTitle(), BorderLayout.NORTH);
              containerpanel.add(createCustOrdDetailsMainPanel(), BorderLayout.CENTER);
              //containerpanel.add(createCustOrdDetailsLeftNavButtons(), BorderLayout.WEST);
              //containerpanel.add(createCustOrdDetailsRightNavButtons(), BorderLayout.EAST);
              containerpanel.add(createCustOrdDetailsButtons(), BorderLayout.SOUTH);
              mainframe.setContentPane(containerpanel);
              mainframe.setLocationRelativeTo(null);
              mainframe.setVisible(true);
              //--<BEGINNING>--Checks to see whether CRecordNumberStore file exists-------------------------------//
              if (OrdRecordNumStore.exists() == true) {
                   recFileExists = true;
              }else {
                   recFileExists = false;
              if (recFileExists == true) {
                   MaxRecord = readRecordNumber();
                   CurrentRecord = MaxRecord;
                   //readOrder();
                   //readInnerOrderRecord(CurrentRecord);
                   System.out.println("Current Record " +CurrentRecord);
                   System.out.println("Max Record " +MaxRecord);
              }else{
                   MaxRecord = 1;
                   writeRecordNumber(MaxRecord);
                   CustOrderIDTxt.setText(""+MaxRecord);
                   System.out.println("Current Record " +CurrentRecord);
                   System.out.println("Max Record " +MaxRecord);
              //--<END>--Checks to see whether CRecordNumberStore file exists--------------------------------------//
              if(readOrder() != null){
                   orderDetails = (CustOrdObject[]) readOrder();
                 innerCustOrdObj = orderDetails[CurrentRecord].getInnerCustOrdObj();
                   MaxItems = orderDetails[CurrentRecord].getMaxItems();
                   if(CurrentRecord > 1 && CurrentRecord < MaxRecord){
                        externalnextbtn.setEnabled(true);
                        externalprevbtn.setEnabled(true);
                   if(CurrentRecord >= MaxRecord){
                        externalnextbtn.setEnabled(false);
                   getFieldText(CurrentRecord-1);
              }else{
                   orderDetails[CurrentRecord] = new CustOrdObject();
                   currentItem = 1;
              return mainframe;
         //--<END>--Creating CustomerOrderDetails Screen---------------------------------------------//
         public JPanel createCustOrdDetailsTitle(){
              createTitlePanel();
              titlepanel.setBackground(TxtfontColor);
              label.setText("- Customer Order Details -");
              labelpanel.setBackground(TxtfontColor);
              label.setForeground(Color.white);
              createbuttonpanel();
              buttonpanel.setBackground(TxtfontColor) ;
              buttonpanel.add(createReturnToMainMenuButton());
              titlepanel.add(labelpanel, BorderLayout.WEST);
              titlepanel.add(buttonpanel, BorderLayout.EAST);
              return titlepanel;
         public JPanel createCustOrdDetailsMainPanel(){
              createmainpanel();
              mainpanel.setBackground(TxtfontColor);
              mainpanel.setLayout(new BorderLayout());          
              mainpanel.setBorder(BorderFactory.createTitledBorder(""));
              mainpanel.add(createInnerTopPanel(), BorderLayout.NORTH);
              mainpanel.add(createInnerCenterPanel(), BorderLayout.CENTER);
              mainpanel.add(createInnerBottomPanel(), BorderLayout.SOUTH);
              mainpanel.add(createInnerRightPanel(), BorderLayout.EAST);
              mainpanel.add(createInnerLeftPanel(), BorderLayout.WEST);
              return mainpanel;
         public JPanel createInnerTopPanel(){
              innertoppanel = new JPanel(new GridBagLayout());
              innertoppanel.setBackground(TxtfontColor);
              GridBagConstraints GBC = new GridBagConstraints();
              GBC.fill = GridBagConstraints.HORIZONTAL;
              //Setting Font Type and Size
              Font font = new Font("Arial", Font.BOLD, 11);
              CustIDLbl = new JLabel("Customer ID");
              CustIDLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              CustIDLbl.setFont(font);
              CustIDLbl.setForeground(LblfontColor);
              GBC.gridx = 1;
              GBC.gridy = 1;
              innertoppanel.add(CustIDLbl, GBC);     
              CustIDTxt = new JTextField(20);
              CustIDTxt.setEditable(true);
              GBC.gridx = 2;
              GBC.gridy = 1;
              innertoppanel.add(CustIDTxt, GBC);
              GBC.gridx = 3;
              GBC.gridy = 1;
              innertoppanel.add(Box.createHorizontalStrut(220), GBC);
              OrderedDateLbl = new JLabel("Order Date");
              OrderedDateLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              OrderedDateLbl.setFont(font);
              OrderedDateLbl.setForeground(LblfontColor);
              GBC.gridx = 4;
              GBC.gridy = 1;
              innertoppanel.add(OrderedDateLbl, GBC);     
              //Get today's date
              Date todaydate = new Date();
              OrderedDateTxt = new JTextField(simpleDF.format(todaydate), 20);
              OrderedDateTxt.setHorizontalAlignment(JTextField.CENTER);
              OrderedDateTxt.setEditable(false);
              GBC.gridx = 5;
              GBC.gridy = 1;
              innertoppanel.add(OrderedDateTxt, GBC);
              CustOrderIDLbl = new JLabel("Customer Order ID");
              CustOrderIDLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              CustOrderIDLbl.setFont(font);
              CustOrderIDLbl.setForeground(LblfontColor);
              GBC.gridx = 1;
              GBC.gridy = 2;
              innertoppanel.add(CustOrderIDLbl, GBC);
              CustOrderIDTxt = new JTextField(20);
              CustOrderIDTxt.setEditable(false);
              GBC.gridx = 2;
              GBC.gridy = 2;
              innertoppanel.add(CustOrderIDTxt, GBC);
              return innertoppanel;
         public JPanel createInnerCenterPanel(){
              innercenterpanel = new JPanel(new GridBagLayout());
              innercenterpanel.setBackground(TxtfontColor);
              innercenterpanel.setBorder(BorderFactory.createLoweredBevelBorder());
              GridBagConstraints GBC = new GridBagConstraints();
              GBC.fill = GridBagConstraints.HORIZONTAL;
              //Setting Font Type and Size
              Font font = new Font("Arial", Font.BOLD, 11);
              ItemNumberLbl = new JLabel("Item Number");
              ItemNumberLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              ItemNumberLbl.setFont(font);
              ItemNumberLbl.setForeground(LblfontColor);
              GBC.gridx = 1;
              GBC.gridy = 1;
              innercenterpanel.add(ItemNumberLbl, GBC);     
              ItemNumberTxt = new JTextField(20);
              GBC.gridx = 2;
              GBC.gridy = 1;
              innercenterpanel.add(ItemNumberTxt, GBC);
              UnitPriceLbl = new JLabel("Unit Price");
              UnitPriceLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              UnitPriceLbl.setFont(font);
              UnitPriceLbl.setForeground(LblfontColor);
              GBC.gridx = 1;
              GBC.gridy = 2;
              innercenterpanel.add(UnitPriceLbl, GBC);     
              UnitPriceTxt = new JTextField(20);
              //UnitPriceTxt.setEditable(false);
              GBC.gridx = 2;
              GBC.gridy = 2;
              innercenterpanel.add(UnitPriceTxt, GBC);
              QuantityReqLbl = new JLabel("Quantity Required");
              QuantityReqLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              QuantityReqLbl.setFont(font);
              QuantityReqLbl.setForeground(LblfontColor);
              GBC.gridx = 1;
              GBC.gridy = 3;
              innercenterpanel.add(QuantityReqLbl, GBC);     
              QuantityReqTxt = new JTextField(20);
              //QuantityReqTxt.setEditable(false);
              GBC.gridx = 2;
              GBC.gridy = 3;
              innercenterpanel.add(QuantityReqTxt, GBC);
              TotPriceLbl = new JLabel("Total Price");
              TotPriceLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              TotPriceLbl.setFont(font);
              TotPriceLbl.setForeground(LblfontColor);
              GBC.gridx = 1;
              GBC.gridy = 4;
              innercenterpanel.add(TotPriceLbl, GBC);     
              TotPriceTxt = new JTextField(20);
              //TotPriceTxt.setEditable(false);
              GBC.gridx = 2;
              GBC.gridy = 4;
              innercenterpanel.add(TotPriceTxt, GBC);
              return innercenterpanel;
         public JPanel createInnerBottomPanel(){
              innerbottompanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
              innerbottompanel.setBackground(TxtfontColor);
              //Setting Font Type and Size
              Font font = new Font("Arial", Font.BOLD, 11);
              GrandTotLbl = new JLabel("Grand Total");
              GrandTotLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              GrandTotLbl.setFont(font);
              GrandTotLbl.setForeground(LblfontColor);
              innerbottompanel.add(GrandTotLbl);
              innerbottompanel.add(Box.createHorizontalStrut(30));
              GrandTotTxt = new JTextField(20);
              innerbottompanel.add(GrandTotTxt);
              return innerbottompanel;
         public JPanel createInnerRightPanel(){
              innerrightpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
              innerrightpanel.setBackground(TxtfontColor);
              innerrightpanel.setLayout(new BoxLayout(navrightpanel, BoxLayout.Y_AXIS));
              innerrightpanel.setBorder(BorderFactory.createLoweredBevelBorder());
              innerrightpanel.setLayout(new GridBagLayout());          
              GridBagConstraints GBC = new GridBagConstraints();
              GBC.fill = GridBagConstraints.HORIZONTAL;
              internalnextbtn = new JButton(createNextButtonIcon());
              GBC.gridx = 1;
              GBC.gridy = 1;
              internalnextbtn.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        //getInnerFieldText(currentItem);
                        internalprevbtn.setEnabled(true);
                        if(currentItem < MaxItems){
                             ++CurrentRecord;
                             //readOrder();
                             //readInnerOrderRecord(CurrentRecord);
                             setInnerFieldText(currentItem);
                             System.out.println(CurrentRecord);//Checking RECORD_NUM
                        if(currentItem == MaxItems){
                             internalnextbtn.setEnabled(false);
              innerrightpanel.add(internalnextbtn, GBC);
              return innerrightpanel;
         public JPanel createInnerLeftPanel(){
              innerleftpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
              innerleftpanel.setBackground(TxtfontColor);
              innerleftpanel.setBorder(BorderFactory.createLoweredBevelBorder());
              innerleftpanel.setForeground(Color.BLACK);
              innerleftpanel.setLayout(new GridBagLayout());          
              GridBagConstraints GBC = new GridBagConstraints();
              GBC.fill = GridBagConstraints.HORIZONTAL;
              internalprevbtn = new JButton(createPreviousButtonIcon());
              GBC.gridx = 1;
              GBC.gridy = 1;
              internalprevbtn.addActionListener(new ActionListener(){
                   public void  actionPerformed(ActionEvent evt){
                        //getInnerFieldText(currentItem);
                        internalnextbtn.setEnabled(true);
                        if(currentItem == 1){
                             internalprevbtn.setEnabled(false);
                        if(currentItem > 0){
                             --currentItem;
                             //readOrder();
                             setInnerFieldText(currentItem);
              innerleftpanel.add(internalprevbtn, GBC);
              return innerleftpanel;
         public JPanel createCustOrdDetailsButtons(){
              createbuttonpanel();
              buttonpanel.setBackground(TxtfontColor);
              externalprevbtn = new JButton(createPreviousButtonIcon());
              externalprevbtn.addActionListener(new ActionListener(){
                   public void  actionPerformed(ActionEvent evt){
                        getFieldText(CurrentRecord);
                        externalnextbtn.setEnabled(true);
                        if(CurrentRecord == 1){
                             externalprevbtn.setEnabled(false);
                        if(CurrentRecord > 0){
                             --CurrentRecord;
                             setFieldText(CurrentRecord);
                             System.out.println(CurrentRecord);//Checking RECORD_NUM
              buttonpanel.add(externalprevbtn);
              addrecordbtn = new JButton("Add Record", createAddButtonIcon());
              addrecordbtn.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        try{
                             MaxRecord = readRecordNumber();
                             MaxRecord++;
                             writeRecordNumber(MaxRecord);
                             //--<BEGINNING>--Clear Fields-------------------------------------------------------//
                             CustIDTxt.setText("");
                             CustOrderIDTxt.setText(""+MaxRecord);
                             //Get today's date
                             Date todaydate = new Date();
                             OrderedDateTxt.setText(""+simpleDF.format(todaydate));
                             ItemNumberTxt.setText("");
                             UnitPriceTxt.setText("");
                             QuantityReqTxt.setText("");
                             TotPriceTxt.setText("");
                             GrandTotTxt.setText("");
                             //--<END>--Clear Fields-------------------------------------------------------------//
                             externalnextbtn.setEnabled(false);
                             externalprevbtn.setEnabled(true);
                             System.out.println(MaxRecord);
                        } catch(Exception ec){ec.printStackTrace();}
              buttonpanel.add(addrecordbtn);
              savebtn = new JButton("Save Data", createSaveButtonIcon());
              savebtn.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        setFieldText(CurrentRecord);
                        writeOrder();
                        writeRecordNumber(MaxRecord);
                        System.out.println(CurrentRecord);
                        System.out.println(MaxRecord);
              buttonpanel.add(savebtn);
              java.net.URL imageURL_AddRowIcon = CommonFeatures.class.getResource("Icons/edit_add.png");
              ImageIcon AddRowIcon = new ImageIcon(imageURL_AddRowIcon);
              additemreqbtn = new JButton("Add Item", AddRowIcon);
              additemreqbtn.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        try{
                             //--<BEGINNING>--Clear Fields-------------------------------------------------------//
                             ItemNumberTxt.setText("");
                             UnitPriceTxt.setText("");
                             QuantityReqTxt.setText("");
                             TotPriceTxt.setText("");
                             //--<END>--Clear Fields-------------------------------------------------------------//
                             //CurrentRecord = MaxRecord;
                             currentItem++;
                             setInnerFieldText(currentItem);
                             internalnextbtn.setEnabled(false);
                             internalprevbtn.setEnabled(true);
                             System.out.println(MaxRecord);
                        } catch(Exception ec){ec.printStackTrace();}
              buttonpanel.add(additemreqbtn);
              externalnextbtn = new JButton(createNextButtonIcon());
              externalnextbtn.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        getFieldText(CurrentRecord);
                        externalprevbtn.setEnabled(true);
                        if(CurrentRecord < MaxRecord){
                             ++CurrentRecord;
                             setFieldText(CurrentRecord);
                             System.out.println(CurrentRecord);//Checking RECORD_NUM
                        if(CurrentRecord == MaxRecord){
                             externalnextbtn.setEnabled(false);
              buttonpanel.add(externalnextbtn);
              return buttonpanel;
         //TODO
         public void setFieldText(int orderID){//TODO
              orderDetails[orderID].setCustID(Integer.parseInt(CustIDTxt.getText()));
              orderDetails[orderID].setCustOrderID(Integer.parseInt(CustOrderIDTxt.getText()));
              orderDetails[orderID].setOrderDate(OrderedDateTxt.getText());
              orderDetails[orderID].setInnerCustOrdObj(innerCustOrdObj);
              orderDetails[orderID].setMaxItems(MaxItems);
              setInnerFieldText(currentItem);
              orderDetails[orderID].setGrandTotal(Float.parseFloat(GrandTotTxt.getText()));
         public void setInnerFieldText(int currentItem){//TODO
              innerCustOrdObj[currentItem] = new InnerCustOrdObject();
              innerCustOrdObj[currentItem].setItemNumber(Integer.parseInt(ItemNumberTxt.getText()));
              innerCustOrdObj[currentItem].setUnitPrice(Float.parseFloat(UnitPriceTxt.getText()));
              innerCustOrdObj[currentItem].setQuantityRequired(Integer.parseInt(QuantityReqTxt.getText()));
              innerCustOrdObj[currentItem].setTotalPrice(Float.parseFloat(TotPriceTxt.getText()));
         public void getFieldText(int orderID){
              CustIDTxt.setText(Integer.toString(orderDetails[orderID].getCustID()));
              CustOrderIDTxt.setText(Integer.toString(orderDetails[orderID].getCustOrderID()));
              OrderedDateTxt.setText(""+orderDetails[orderID].getOrderDate());          
              currentItem = orderDetails[orderID].getMaxItems();
              System.err.println("currentItem" + currentItem);
              getInnerFieldText(currentItem);
              GrandTotTxt.setText(Float.toString(orderDetails[orderID].getGrandTotal()));
         public void getInnerFieldText(int currentItem){
              ItemNumberTxt.setText(Integer.toString(innerCustOrdObj[currentItem].getItemNumber()));
              UnitPriceTxt.setText(Float.toString(innerCustOrdObj[currentItem].getUnitPrice()));
              QuantityReqTxt.setText(Integer.toString(innerCustOrdObj[currentItem].getQuantityRequired()));
              TotPriceTxt.setText(Float.toString(innerCustOrdObj[currentItem].getTotalPrice()));
         public void writeOrder(){//TODO
              try {
                   objOut = new ObjectOutputStream(new FileOutputStream(OrderDetailsFile));
                   objOut.writeObject(orderDetails);
                   System.out.println("WORKING!");
                   objOut.flush();
                   objOut.close();
              } catch (IOException e) {
                   e.printStackTrace();
         public Object readOrder(){
              Object temporaryObj;
              try{
                   objIn = new ObjectInputStream(new FileInputStream(OrderDetailsFile));
                   temporaryObj = objIn.readObject();               
                   CustOrdObject[] blah = (CustOrdObject[]) temporaryObj;
                   System.out.println("Outer: "+blah[1].getCustID());
                   InnerCustOrdObject[] whee = blah[1].getInnerCustOrdObj();
                   System.out.println("Inner: "+whee[1].getItemNumber());
                   objIn.close();
                   System.out.println("Read Worky!");
                   return temporaryObj;
              }catch(Exception e){
                   e.printStackTrace();
                   System.out.println("Read No Worky!");
                   return null;
         public void writeRecordNumber(int MaxRecord){
              try{
                   objOut = new ObjectOutputStream(new FileOutputStream(OrdRecordNumStore));
                   objOut.writeObject(MaxRecord);
                   System.out.println("WORKING!");
                   objOut.flush();
                   objOut.close();
              }catch(Exception e){e.printStackTrace();}
         public int readRecordNumber() {
              try {
                   objIn = new ObjectInputStream(new FileInputStream(OrdRecordNumStore));
                   int temporaryObj = Integer.parseInt(objIn.readObject().toString());
                   objIn.close();
                   System.out.println("Read Number Worky!");
                   return temporaryObj;
              } catch (Exception e) {
                   e.printStackTrace();
                   System.out.println("Read Number No Worky!");
                   return -1;
    }Message was edited by:
    Kilik07
    Message was edited by:
    Kilik07

    ok i got reading to work to a certain extent... but the prob is i cnt seem to save my innerCustOrdObj proprly...when ever i look for a record using the gotorecordbtn, the outerobject, which is the orderDetails, seems to change but the innerCustOrdObj remains the same... heres the new code..
    public class CustomerOrderDetails extends CommonFeatures{
         //TODO
         private static int MAX_ORDERS = 200;
         private static int MAX_ORDERITEMS = 100;
         private static int MaxRecord;
         private static int CurrentRecord = 1;
         private static int currentItem;
         private static int MaxItems = 1;
         private static boolean FileExists, recFileExists;
         private static boolean RecordExists;
         private static CustOrdObject[] orderDetails = new CustOrdObject[MAX_ORDERS];
         private static InnerCustOrdObject[] innerCustOrdObj = new InnerCustOrdObject[MAX_ORDERITEMS];     
         private static File OrderDetailsFile = new File("CustOrdDetails.ser");
         private static File OrdRecordNumStore = new File("OrdRecordNumStore.txt");
         private static PrintWriter writeFile;
         private static BufferedReader readFile;
         private static ObjectOutputStream objOut;
         private static ObjectInputStream objIn;
         //Set format for date
         SimpleDateFormat simpleDF = new SimpleDateFormat("dd MM yyyy");
         //--<BEGINNING>--Declaring Interface Variables------------------------------------------//
         private JPanel innertoppanel, innercenterpanel, innerbottompanel, innerrightpanel, innerleftpanel;
         private JLabel CustIDLbl, CustOrderIDLbl, OrderedDateLbl, GrandTotLbl, ItemNumberLbl,UnitPriceLbl, QuantityReqLbl, TotPriceLbl;
         private JTextField CustIDTxt, CustOrderIDTxt, OrderedDateTxt, GrandTotTxt, ItemNumberTxt, UnitPriceTxt, QuantityReqTxt, TotPriceTxt;
         private JButton addrecordbtn, savebtn, externalprevbtn, externalnextbtn, internalprevbtn, internalnextbtn, gotorecordbtn, additemreqbtn;
         //--<END>--Declaring Interface Variables------------------------------------------------//
         public static void main(String[] args) {
              final CustomerOrderDetails COD = new CustomerOrderDetails();
              java.awt.EventQueue.invokeLater(new Runnable() {
                   public void run() {
                        try {
                             UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                             COD.createCustOrdDetailsScreen();
                        } catch (Exception eb) {
                             eb.printStackTrace();
         //--<BEGINNING>--Creating CustomerOrderDetails Screen---------------------------------------//
         public JFrame createCustOrdDetailsScreen() {
              createDefaultFrame();
              mainframe.setSize(800,500);
              createContainerPanel();
              containerpanel.add(createCustOrdDetailsTitle(), BorderLayout.NORTH);
              containerpanel.add(createCustOrdDetailsMainPanel(), BorderLayout.CENTER);
              //containerpanel.add(createCustOrdDetailsLeftNavButtons(), BorderLayout.WEST);
              //containerpanel.add(createCustOrdDetailsRightNavButtons(), BorderLayout.EAST);
              containerpanel.add(createCustOrdDetailsButtons(), BorderLayout.SOUTH);
              mainframe.setContentPane(containerpanel);
              mainframe.setLocationRelativeTo(null);
              mainframe.setVisible(true);
              //--<BEGINNING>--Checks to see whether CRecordNumberStore file exists-------------------------------//
              if (OrdRecordNumStore.exists() == true) {
                   recFileExists = true;
              }else {
                   recFileExists = false;
              if (recFileExists == true) {
                   MaxRecord = readRecordNumber();
                   CurrentRecord = MaxRecord;
                   //readOrder();
                   //readInnerOrderRecord(CurrentRecord);
                   System.out.println("Current Record " +CurrentRecord);
                   System.out.println("Max Record " +MaxRecord);
              }else{
                   MaxRecord = 1;
                   writeRecordNumber(MaxRecord);
                   CustOrderIDTxt.setText(""+MaxRecord);
                   System.out.println("Current Record " +CurrentRecord);
                   System.out.println("Max Record " +MaxRecord);
              //--<END>--Checks to see whether CRecordNumberStore file exists--------------------------------------//
              if(readOrder() != null){
                   orderDetails = (CustOrdObject[]) readOrder();
                   //CurrentRecord--;
                   //System.out.println("Current Rec Here"+CurrentRecord);
                   if(orderDetails[CurrentRecord] == null){
                        System.err.println("CustomerOrderObj 1 is null !!");
                   }else{
                        System.err.println("CustomerOrderObj 1 is  not null !!");
                   if(orderDetails[CurrentRecord].getInnerCustOrdObj() == null){
                        System.err.println("InnerCustomerOrderObj is null !!");
                   }else{
                        System.err.println("InnerCustomerOrderObj is  not null !!");
                   innerCustOrdObj = orderDetails[CurrentRecord].getInnerCustOrdObj();
                   MaxItems = orderDetails[CurrentRecord].getMaxItems();
                   if(CurrentRecord > 1 && CurrentRecord < MaxRecord){
                        externalnextbtn.setEnabled(true);
                        externalprevbtn.setEnabled(true);
                   if(CurrentRecord >= MaxRecord){
                        externalnextbtn.setEnabled(false);
                   getFieldText(CurrentRecord);
                   getInnerFieldText(MaxItems);
              }else{
                   orderDetails[CurrentRecord] = new CustOrdObject();
                   currentItem = 1;
              return mainframe;
         //--<END>--Creating CustomerOrderDetails Screen---------------------------------------------//
         public JPanel createCustOrdDetailsTitle(){
              createTitlePanel();
              titlepanel.setBackground(TxtfontColor);
              label.setText("- Customer Order Details -");
              labelpanel.setBackground(TxtfontColor);
              label.setForeground(Color.white);
              createbuttonpanel();
              buttonpanel.setBackground(TxtfontColor) ;
              buttonpanel.add(createReturnToMainMenuButton());
              titlepanel.add(labelpanel, BorderLayout.WEST);
              titlepanel.add(buttonpanel, BorderLayout.EAST);
              return titlepanel;
         public JPanel createCustOrdDetailsMainPanel(){
              createmainpanel();
              mainpanel.setBackground(TxtfontColor);
              mainpanel.setLayout(new BorderLayout());          
              mainpanel.setBorder(BorderFactory.createTitledBorder(""));
              mainpanel.add(createInnerTopPanel(), BorderLayout.NORTH);
              mainpanel.add(createInnerCenterPanel(), BorderLayout.CENTER);
              mainpanel.add(createInnerBottomPanel(), BorderLayout.SOUTH);
              mainpanel.add(createInnerRightPanel(), BorderLayout.EAST);
              mainpanel.add(createInnerLeftPanel(), BorderLayout.WEST);
              return mainpanel;
         public JPanel createInnerTopPanel(){
              innertoppanel = new JPanel(new GridBagLayout());
              innertoppanel.setBackground(TxtfontColor);
              GridBagConstraints GBC = new GridBagConstraints();
              GBC.fill = GridBagConstraints.HORIZONTAL;
              //Setting Font Type and Size
              Font font = new Font("Arial", Font.BOLD, 11);
              CustIDLbl = new JLabel("Customer ID");
              CustIDLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              CustIDLbl.setFont(font);
              CustIDLbl.setForeground(LblfontColor);
              GBC.gridx = 1;
              GBC.gridy = 1;
              innertoppanel.add(CustIDLbl, GBC);     
              CustIDTxt = new JTextField(20);
              CustIDTxt.setEditable(true);
              GBC.gridx = 2;
              GBC.gridy = 1;
              innertoppanel.add(CustIDTxt, GBC);
              GBC.gridx = 3;
              GBC.gridy = 1;
              innertoppanel.add(Box.createHorizontalStrut(220), GBC);
              OrderedDateLbl = new JLabel("Order Date");
              OrderedDateLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              OrderedDateLbl.setFont(font);
              OrderedDateLbl.setForeground(LblfontColor);
              GBC.gridx = 4;
              GBC.gridy = 1;
              innertoppanel.add(OrderedDateLbl, GBC);     
              //Get today's date
              Date todaydate = new Date();
              OrderedDateTxt = new JTextField(simpleDF.format(todaydate), 20);
              OrderedDateTxt.setHorizontalAlignment(JTextField.CENTER);
              OrderedDateTxt.setEditable(false);
              GBC.gridx = 5;
              GBC.gridy = 1;
              innertoppanel.add(OrderedDateTxt, GBC);
              CustOrderIDLbl = new JLabel("Customer Order ID");
              CustOrderIDLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              CustOrderIDLbl.setFont(font);
              CustOrderIDLbl.setForeground(LblfontColor);
              GBC.gridx = 1;
              GBC.gridy = 2;
              innertoppanel.add(CustOrderIDLbl, GBC);
              CustOrderIDTxt = new JTextField(20);
              //CustOrderIDTxt.setEditable(false);
              GBC.gridx = 2;
              GBC.gridy = 2;
              innertoppanel.add(CustOrderIDTxt, GBC);
              return innertoppanel;
         public JPanel createInnerCenterPanel(){
              innercenterpanel = new JPanel(new GridBagLayout());
              innercenterpanel.setBackground(TxtfontColor);
              innercenterpanel.setBorder(BorderFactory.createLoweredBevelBorder());
              GridBagConstraints GBC = new GridBagConstraints();
              GBC.fill = GridBagConstraints.HORIZONTAL;
              //Setting Font Type and Size
              Font font = new Font("Arial", Font.BOLD, 11);
              ItemNumberLbl = new JLabel("Item Number");
              ItemNumberLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              ItemNumberLbl.setFont(font);
              ItemNumberLbl.setForeground(LblfontColor);
              GBC.gridx = 1;
              GBC.gridy = 1;
              innercenterpanel.add(ItemNumberLbl, GBC);     
              ItemNumberTxt = new JTextField(20);
              GBC.gridx = 2;
              GBC.gridy = 1;
              innercenterpanel.add(ItemNumberTxt, GBC);
              UnitPriceLbl = new JLabel("Unit Price");
              UnitPriceLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              UnitPriceLbl.setFont(font);
              UnitPriceLbl.setForeground(LblfontColor);
              GBC.gridx = 1;
              GBC.gridy = 2;
              innercenterpanel.add(UnitPriceLbl, GBC);     
              UnitPriceTxt = new JTextField(20);
              //UnitPriceTxt.setEditable(false);
              GBC.gridx = 2;
              GBC.gridy = 2;
              innercenterpanel.add(UnitPriceTxt, GBC);
              QuantityReqLbl = new JLabel("Quantity Required");
              QuantityReqLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              QuantityReqLbl.setFont(font);
              QuantityReqLbl.setForeground(LblfontColor);
              GBC.gridx = 1;
              GBC.gridy = 3;
              innercenterpanel.add(QuantityReqLbl, GBC);     
              QuantityReqTxt = new JTextField(20);
              //QuantityReqTxt.setEditable(false);
              GBC.gridx = 2;
              GBC.gridy = 3;
              innercenterpanel.add(QuantityReqTxt, GBC);
              TotPriceLbl = new JLabel("Total Price");
              TotPriceLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              TotPriceLbl.setFont(font);
              TotPriceLbl.setForeground(LblfontColor);
              GBC.gridx = 1;
              GBC.gridy = 4;
              innercenterpanel.add(TotPriceLbl, GBC);     
              TotPriceTxt = new JTextField(20);
              TotPriceTxt.setEditable(false);
              TotPriceTxt.addFocusListener(new FocusAdapter(){
                   public void focusGained(FocusEvent evt){
                        TotPriceTxt.setText(""+Integer.parseInt(UnitPriceTxt.getText())*Integer.parseInt(QuantityReqTxt.getText()));
              GBC.gridx = 2;
              GBC.gridy = 4;
              innercenterpanel.add(TotPriceTxt, GBC);
              return innercenterpanel;
         public JPanel createInnerBottomPanel(){
              innerbottompanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
              innerbottompanel.setBackground(TxtfontColor);
              //Setting Font Type and Size
              Font font = new Font("Arial", Font.BOLD, 11);
              GrandTotLbl = new JLabel("Grand Total");
              GrandTotLbl.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              GrandTotLbl.setFont(font);
              GrandTotLbl.setForeground(LblfontColor);
              innerbottompanel.add(GrandTotLbl);
              innerbottompanel.add(Box.createHorizontalStrut(30));
              GrandTotTxt = new JTextField(20);
              innerbottompanel.add(GrandTotTxt);
              return innerbottompanel;
         public JPanel createInnerRightPanel(){
              innerrightpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
              innerrightpanel.setBackground(TxtfontColor);
              innerrightpanel.setLayout(new BoxLayout(navrightpanel, BoxLayout.Y_AXIS));
              innerrightpanel.setBorder(BorderFactory.createLoweredBevelBorder());
              innerrightpanel.setLayout(new GridBagLayout());          
              GridBagConstraints GBC = new GridBagConstraints();
              GBC.fill = GridBagConstraints.HORIZONTAL;
              internalnextbtn = new JButton(createNextButtonIcon());
              GBC.gridx = 1;
              GBC.gridy = 1;
              internalnextbtn.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        getInnerFieldText(currentItem);
                        internalprevbtn.setEnabled(true);
                        if(currentItem < MaxItems){
                             ++currentItem;
                             orderDetails[CurrentRecord].getInnerCustOrdObj();
                             setInnerFieldText(currentItem);
                             System.out.println("Current Item" + currentItem);
                        if(currentItem == MaxItems){
                             internalnextbtn.setEnabled(false);
              innerrightpanel.add(internalnextbtn, GBC);
              return innerrightpanel;
         public JPanel createInnerLeftPanel(){
              innerleftpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
              innerleftpanel.setBackground(TxtfontColor);
              innerleftpanel.setBorder(BorderFactory.createLoweredBevelBorder());
              innerleftpanel.setForeground(Color.BLACK);
              innerleftpanel.setLayout(new GridBagLayout());          
              GridBagConstraints GBC = new GridBagConstraints();
              GBC.fill = GridBagConstraints.HORIZONTAL;
              internalprevbtn = new JButton(createPreviousButtonIcon());
              GBC.gridx = 1;
              GBC.gridy = 1;
              internalprevbtn.addActionListener(new ActionListener(){
                   public void  actionPerformed(ActionEvent evt){
                        getInnerFieldText(currentItem);
                        internalnextbtn.setEnabled(true);
                        if(currentItem == 1){
                             internalprevbtn.setEnabled(false);
                        if(currentItem > 0){
                             --currentItem;
                             orderDetails[CurrentRecord].getInnerCustOrdObj();
                             setInnerFieldText(currentItem);
                             System.out.println("Current Item" + currentItem);
              innerleftpanel.add(internalprevbtn, GBC);
              return innerleftpanel;
         public JPanel createCustOrdDetailsButtons(){
              createbuttonpanel();
              buttonpanel.setBackground(TxtfontColor);
              externalprevbtn = new JButton(createPreviousButtonIcon());
              externalprevbtn.addActionListener(new ActionListener(){
                   public void  actionPerformed(ActionEvent evt){
                        getFieldText(CurrentRecord);
                        externalnextbtn.setEnabled(true);
                        if(CurrentRecord == 1){
                             externalprevbtn.setEnabled(false);
                        if(CurrentRecord > 0){
                             --CurrentRecord;
                             setFieldText(CurrentRecord);
                             System.out.println("Current Record " + CurrentRecord);//Checking RECORD_NUM
              buttonpanel.add(externalprevbtn);
              addrecordbtn = new JButton("Add Record", createAddButtonIcon());
              addrecordbtn.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        try{
                             MaxRecord = readRecordNumber();
                             MaxRecord++;
                             CurrentRecord = MaxRecord;
                             orderDetails[CurrentRecord] = new CustOrdObject();
                             writeRecordNumber(MaxRecord);
                             MaxItems = 1;
                             innerCustOrdObj[MaxItems] = new InnerCustOrdObject();
                             //--<BEGINNING>--Clear Fields-------------------------------------------------------//
                             CustIDTxt.setText("");
                             CustOrderIDTxt.setText(""+MaxRecord);
                             //Get today's date
                             Date todaydate = new Date();
                             OrderedDateTxt.setText(""+simpleDF.format(todaydate));
                             ItemNumberTxt.setText("");
                             UnitPriceTxt.setText("");
                             QuantityReqTxt.setText("");
                             TotPriceTxt.setText("");
                             GrandTotTxt.setText("");
                             //--<END>--Clear Fields-------------------------------------------------------------//
                             externalnextbtn.setEnabled(false);
                             externalprevbtn.setEnabled(true);
                             System.out.println(MaxRecord);
                        } catch(Exception ec){ec.printStackTrace();}
              buttonpanel.add(addrecordbtn);
              savebtn = new JButton("Save Data", createSaveButtonIcon());
              savebtn.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        setFieldText(CurrentRecord);
                        setInnerFieldText(MaxItems);
                        writeOrder();
                        writeRecordNumber(MaxRecord);
                        System.out.println(CurrentRecord);
                        System.out.println(MaxRecord);
              buttonpanel.add(savebtn);
              java.net.URL imageURL_AddRowIcon = CommonFeatures.class.getResource("Icons/edit_add.png");
              ImageIcon AddRowIcon = new ImageIcon(imageURL_AddRowIcon);
              additemreqbtn = new JButton("Add Item", AddRowIcon);
              additemreqbtn.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        try{
                             //--<BEGINNING>--Clear Fields-------------------------------------------------------//
                             ItemNumberTxt.setText("");
                             UnitPriceTxt.setText("");
                             QuantityReqTxt.setText("");
                             TotPriceTxt.setText("");
                             //--<END>--Clear Fields-------------------------------------------------------------//
                             //CurrentRecord = MaxRecord;
                             MaxItems++;
                             innerCustOrdObj[MaxItems] = new InnerCustOrdObject();
                             System.out.println("Max Items "+MaxItems);
                             currentItem = MaxItems;
                             orderDetails[CurrentRecord].setMaxItems(MaxItems);
                             ///setInnerFieldText(currentItem);
                             internalnextbtn.setEnabled(false);
                             internalprevbtn.setEnabled(true);
                        } catch(Exception ec){ec.printStackTrace();}
              buttonpanel.add(additemreqbtn);
              externalnextbtn = new JButton(createNextButtonIcon());
              externalnextbtn.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent evt){
                        getFieldText(CurrentRecord);
                        externalprevbtn.setEnabled(true);
                        if(CurrentRecord < MaxRecord){
                             ++CurrentRecord;
                             setFieldText(CurrentRecord);
                             System.out.println(CurrentRecord);//Checking RECORD_NUM
                        if(CurrentRecord == MaxRecord){
                             externalnextbtn.setEnabled(false);
              buttonpanel.add(externalnextbtn);
              gotorecordbtn = new JButton("Go To Record", createGotoButtonIcon());
              gotorecordbtn.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent evt){
                         * The text from the GotorecordTxt textfield will be taken and assigned
                         * to a temporary integer variable called Find. 
                        int Find = Integer.parseInt(CustOrderIDTxt.getText());
                        for(int j=1; j <= MaxRecord; j++){
                              * Using a for loop, each record can be read using the readCustRecord
                              * method.
                             getFieldText(j);
                              * An if condition is utilized to check whether the temporary stored variable, Find,
                              * matches a field in a record. If this record is found, then using the RecordExists
                              * which was declared at the top, either a true or false statement can be assigned
                              * If the record exists, then a true statement will be assigned, if not a false
                              * statement will be assigned.
                             if(orderDetails[j].getCustOrderID() == Find){
                                  RecordExists = true;
                                  break;
                             }else{
                                  RecordExists = false;
                        if(RecordExists == false){
                              * If the RecordExists is assigned a false statement, then a message will be
                              * displayed to show that the record does not exist.
                             JOptionPane.showMessageDialog(null, "Record Does Not Exist!", "Error Message", JOptionPane.ERROR_MESSAGE, createErrorIcon());
                        }else{
                             getFieldText(Find);
              buttonpanel.add(gotorecordbtn);
              return buttonpanel;
         //TODO
         public void setFieldText(int orderID){//TODO
              orderDetails[orderID].setCustID(Integer.parseInt(CustIDTxt.getText()));
              orderDetails[orderID].setCustOrderID(Integer.parseInt(CustOrderIDTxt.getText()));
              orderDetails[orderID].setOrderDate(OrderedDateTxt.getText());
              orderDetails[orderID].setInnerCustOrdObj(innerCustOrdObj);
              orderDetails[orderID].setMaxItems(MaxItems);
              setInnerFieldText(currentItem);
              orderDetails[orderID].setGrandTotal(Float.parseFloat(GrandTotTxt.getText()));
         public void setInnerFieldText(int currentItem){//TODO
              innerCustOrdObj[currentItem] = new InnerCustOrdObject();
              innerCustOrdObj[currentItem].setMaxItems(MaxItems);
              innerCustOrdObj[currentItem].setItemNumber(Integer.parseInt(ItemNumberTxt.getText()));
              innerCustOrdObj[currentItem].setUnitPrice(Float.parseFloat(UnitPriceTxt.getText()));
              innerCustOrdObj[currentItem].setQuantityRequired(Integer.parseInt(QuantityReqTxt.getText()));
              innerCustOrdObj[currentItem].setTotalPrice(Float.parseFloat(TotPriceTxt.getText()));
         public void getFieldText(int orderID){
              CustIDTxt.setText(Integer.toString(orderDetails[orderID].getCustID()));
              CustOrderIDTxt.setText(Integer.toString(orderDetails[orderID].getCustOrderID()));
              OrderedDateTxt.setText(""+orderDetails[orderID].getOrderDate());          
              currentItem = orderDetails[orderID].getMaxItems();
              orderDetails[orderID].getInnerCustOrdObj();
              System.err.println("currentItem" + currentItem);
              //getInnerFieldText(currentItem);
              GrandTotTxt.setText(Float.toString(orderDetails[orderID].getGrandTotal()));
         public void getInnerFieldText(int currentItem){
              ItemNumberTxt.setText(Integer.toString(innerCustOrdObj[currentItem].getItemNumber()));
              UnitPriceTxt.setText(Float.toString(innerCustOrdObj[currentItem].getUnitPrice()));
              QuantityReqTxt.setText(Integer.toString(innerCustOrdObj[currentItem].getQuantityRequired()));
              TotPriceTxt.setText(Float.toString(innerCustOrdObj[currentItem].getTotalPrice()));
         public void writeOrder(){//TODO
              try {
                   objOut = new ObjectOutputStream(new FileOutputStream(OrderDetailsFile));
                   objOut.writeObject(orderDetails);
                   System.out.println("WORKING!");
                   objOut.flush();
                   objOut.close();
              } catch (IOException e) {
                   e.printStackTrace();
         public Object readOrder(){
              Object temporaryObj;
              try{
                   objIn = new ObjectInputStream(new FileInputStream(OrderDetailsFile));
                   temporaryObj = objIn.readObject();               
                   CustOrdObject[] blah = (CustOrdObject[]) temporaryObj;
                   /*               System.out.println("Outer: "+blah[1].getCustID());
                   InnerCustOrdObject[] whee = blah[1].getInnerCustOrdObj();
                   System.out.println("Inner: "+whee[1].getItemNumber());*/
                   objIn.close();
                   System.out.println("Read Worky!");
                   return temporaryObj;
              }catch(Exception e){
                   e.printStackTrace();
                   System.out.println("Read No Worky!");
                   return null;
         public void writeRecordNumber(int MaxRecord){
              try{
                   objOut = new ObjectOutputStream(new FileOutputStream(OrdRecordNumStore));
                   objOut.writeObject(MaxRecord);
                   System.out.println("WORKING!");
                   objOut.flush();
                   objOut.close();
              }catch(Exception e){e.printStackTrace();}
         public int readRecordNumber() {
              try {
                   objIn = new ObjectInputStream(new FileInputStream(OrdRecordNumStore));
                   int temporaryObj = Integer.parseInt(objIn.readObject().toString());
                   objIn.close();
                   System.out.println("Read Number Worky!");
                   return temporaryObj;
              } catch (Exception e) {
                   e.printStackTrace();
                   System.out.println("Read Number No Worky!");
                   return -1;
    }Message was edited by:
    Kilik07

  • Problem with setMnemonic after upgrading to 1.4.2

    Hi,
    setMnemonic doesnt seem to work properly for JButtons after upgrading from 1.3.1 to 1.4.1. Hot Key works but underlining doesnt show.
    In our app, we have our own controls which are basically derived from Swing controls. In this case JButton.
    I have tried using both setMnemonic API (char as well as int) but no luck. Look and feel we use is Windows look and feel (W2K). Font is Dialog. One thing I have noticed is that if I donot set the look and feel in my app. It seems to work fine. (Metalic).
    Anybody has any clue on how to fix this issue ?
    Thanks in advance
    Sohan

    Hi,
    Here is a code sample for the above problem.
    import java.awt.*;
    import javax.swing.*;
    public class TestFrame {
              public static void main(String[] args) {
                        JButton button = new JButton();
                        JFrame frame = new JFrame();
                        // Add button to the frame
                        //frame.getContentPane().setLayout(new GridBagLayout());
                        //frame.getContentPane().add(button, new GridBagConstraints(3,2,1,1,1.0,1.0,GridBagConstraints.SOUTHEAST,GridBagConstraints.NONE,new Insets (0,0,0,0),0,0));
                        frame.getContentPane().add(button, BorderLayout.NORTH);
                        // Set initial size
                        int frameWidth = 300;
                        int frameHeight = 300;
                        frame.setSize(frameWidth, frameHeight);
                        button.setText ("Button");
                        button.setMnemonic((int)'o' );
                        button.setMargin(new Insets (0,0,0,0));
                        button.setSize (new Dimension (73,21));
                        button.setFont(new Font ("Dialog", Font.PLAIN, 11));
                   try {
                        UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
                        SwingUtilities.updateComponentTreeUI(frame);
                   catch (Exception e){};
                        // Show the frame
                        frame.pack();
                        frame.setVisible(true);
    Sohan

  • JTabbedPane, JPane PROBLEM

    Hi!, I have a several problem with JApplet, this is the code:
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.io.*;
    import java.awt.*;
    public class NuevoApplet extends JApplet{
    JMenuBar menuBar;
    JMenu menuArchivo, submenu;
    JMenuItem menuNuevo;
    JTabbedPane Tabbed1 = new JTabbedPane();
    JPanel Panel = new JPanel();
    class EventHandler implements ActionListener
              public void actionPerformed(ActionEvent e)
                   //Si se elige salir en el menu
                   if (e.getSource() == menuNuevo)
                        CreaTab();
    ActionListener eventHandler = new EventHandler();
    public void start(){}
    public void init () {
    try {
    UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
    } catch (Exception e) { }
    Panel.setBorder(BorderFactory.createEtchedBorder());
    Panel.setLayout(new java.awt.BorderLayout());
    this.Panel.updateUI();
    this.setContentPane(this.Panel);
    this.CreaMenus();
    this.getContentPane().add(this.Tabbed1,java.awt.BorderLayout.CENTER);
    initConnections();
    private void CreaMenus(){
    //Creamos la barra de men�s
    menuBar = new JMenuBar();
    this.setJMenuBar(menuBar);
    //Creamos el men� de Archivo
    menuArchivo = new JMenu("Archivo");
    menuBar.add(menuArchivo);
    //Creamos los elementos del men� archivo
    menuNuevo = new JMenuItem("Abrir Archivo *.hex");
    menuArchivo.add(menuNuevo);     
    public void initConnections()
    //se suscriben todas las componentes que quieren escuchar los eventos
         menuNuevo.addActionListener(eventHandler);
    public void CreaTab(){
    JPanel a = new JPanel();
    Entorno1 b = new Entorno1();
    a.add(new JButton("BOTON1"),java.awt.BorderLayout.CENTER);
    a.add(new JButton("BOTON2"),java.awt.BorderLayout.EAST);
    this.Tabbed1.addTab("Primera Pesta�a", b); --> PROBLEM, not insert the JPanel b extends Entorno1
         b.repaint();
         Tabbed1.invalidate();
    Tabbed1.getParent().invalidate();
    Tabbed1.validate();
    Tabbed1.repaint();
         this.Tabbed1.updateUI();
         /*this.Tabbed1.validate();
         this.Tabbed1.updateUI();
         this.Tabbed1.revalidate();*/
    public class Entorno1 extends JPanel{
    public void Entorno1(){
         setLayout(new BorderLayout());
         Border raisedBevel = BorderFactory.createRaisedBevelBorder();
    Border loweredBevel = BorderFactory.createLoweredBevelBorder();
    Border compound = BorderFactory.createCompoundBorder
    (raisedBevel, loweredBevel);
    this.setBorder(compound);
    this.add(new JButton("Boton1"),java.awt.BorderLayout.CENTER);
    this.add(new JButton("Boton2"),java.awt.BorderLayout.EAST);
    this.updateUI();
    this.setVisible(true);
    this.revalidate();
    this.repaint();
    } //Fin de la clase Applet16F84
    When I use b extends Entorno1 and I insert as JPanel of JTabbedPane, not show it.
    this.Tabbed1.addTab("Primera Pesta�a", b);
    But this yes show it:
    this.Tabbed1.addTab("Primera Pesta�a", a);
    Why ? ..
    Thanks !

    Your constructor is actually a method and not a constructor.
    Therefore calling new Entorno1() returns you a blank panel.
    change this
    public void Entorno1(){
    ...to this.
    public Entorno1(){that should do it..
    nes

  • No problem with sdk 1.3- problem with 1.4!!!

    I am trying to make an interface using swing objects..
    The buttons are looking like images (2D) when compiling and running the program with sdk 1.4...
    although if I use 1.3 everything is ok??
    even with the new java version I still have the same problem..
    has anyone any idea how to fix this??
    thx in advance!

    /*                      BET                                 */
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
      * Summary description for BET
    public class BET extends JFrame
         // Variables declaration
         private JLabel jLabel1;
         private JLabel jLabel2;
         private JLabel jLabel3;
         private JTextField jTextField1;
         private JTextField jTextField2;
         private JTextField jTextField3;
         private JTextField jTextField4;
         private JTextField jTextField6;
         private JButton jButton1;
         private JButton jButton2;
         private JPanel contentPane;
         // End of variables declaration
         public BET()
              super();
              initializeComponent();
              // TODO: Add any constructor code after initializeComponent call
              this.setVisible(true);
          * This method is called from within the constructor to initialize the form.
          * WARNING: Do NOT modify this code. The content of this method is always regenerated
          * by the Windows Form Designer. Otherwise, retrieving design might not work properly.
          * Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
          * to retrieve your design properly in future, before revising this method.
         private void initializeComponent()
              jLabel1 = new JLabel();
              jLabel2 = new JLabel();
              jLabel3 = new JLabel();
              jTextField1 = new JTextField();
              jTextField2 = new JTextField();
              jTextField3 = new JTextField();
              jTextField4 = new JTextField();
              jTextField6 = new JTextField();
              jButton1 = new JButton();
              jButton2 = new JButton();
              contentPane = (JPanel)this.getContentPane();
              // jLabel1
              jLabel1.setForeground(new Color(59, 241, 227));
              jLabel1.setText("<HTML><B><U>QUESTION</B><HTML>");
              // jLabel2
              jLabel2.setForeground(new Color(50, 245, 113));
              jLabel2.setText("<HTML><B><U>CHOICE</B><HTML>");
              // jLabel3
              jLabel3.setForeground(new Color(50, 245, 113));
              jLabel3.setText("<HTML><B><U>POINTS</B><HTML>");
              // jTextField1
              jTextField1.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jTextField1_actionPerformed(e);
              // jTextField2
              jTextField2.setText("YES");
              jTextField2.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jTextField2_actionPerformed(e);
              // jTextField3
              jTextField3.setText("10");
              jTextField3.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jTextField3_actionPerformed(e);
              // jTextField4
              jTextField4.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jTextField4_actionPerformed(e);
              // jTextField6
              jTextField6.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jTextField6_actionPerformed(e);
              // jButton1
              jButton1.setBackground(new Color(117, 158, 145));
              jButton1.setText("OK");
              jButton1.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jButton1_actionPerformed(e);
              // jButton2
              jButton2.setBackground(new Color(117, 158, 145));
              jButton2.setText("CANCEL");
              jButton2.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e)
                        jButton2_actionPerformed(e);
              // contentPane
              contentPane.setLayout(null);
              contentPane.setBackground(new Color(67, 97, 83));
              addComponent(contentPane, jLabel1, 172,8,60,18);
              addComponent(contentPane, jLabel2, 73,78,60,18);
              addComponent(contentPane, jLabel3, 211,76,60,18);
              addComponent(contentPane, jTextField1, 9,27,403,28);
              addComponent(contentPane, jTextField2, 24,101,134,22);
              addComponent(contentPane, jTextField3, 203,101,51,22);
              addComponent(contentPane, jTextField4, 21,151,137,22);
              addComponent(contentPane, jTextField6, 18,200,140,22);
              addComponent(contentPane, jButton1, 299,188,80,70);
              addComponent(contentPane, jButton2, 299,90,80,70);
              // BET
              this.setTitle("BET");
              this.setLocation(new Point(-2, 1));
              this.setSize(new Dimension(424, 316));
         /** Add Component Without a Layout Manager (Absolute Positioning) */
         private void addComponent(Container container,Component c,int x,int y,int width,int height)
              c.setBounds(x,y,width,height);
              container.add(c);
         // TODO: Add any appropriate code in the following Event Handling Methods
         private void jTextField1_actionPerformed(ActionEvent e)
              System.out.println("\njTextField1_actionPerformed(ActionEvent e) called.");
              // TODO: Add any handling code here
         private void jTextField2_actionPerformed(ActionEvent e)
              System.out.println("\njTextField2_actionPerformed(ActionEvent e) called.");
              // TODO: Add any handling code here
         private void jTextField3_actionPerformed(ActionEvent e)
              System.out.println("\njTextField3_actionPerformed(ActionEvent e) called.");
              // TODO: Add any handling code here
         private void jTextField4_actionPerformed(ActionEvent e)
              System.out.println("\njTextField4_actionPerformed(ActionEvent e) called.");
              // TODO: Add any handling code here
         private void jTextField6_actionPerformed(ActionEvent e)
              System.out.println("\njTextField6_actionPerformed(ActionEvent e) called.");
              // TODO: Add any handling code here
         private void jButton1_actionPerformed(ActionEvent e)
              System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
              // TODO: Add any handling code here
         private void jButton2_actionPerformed(ActionEvent e)
              System.out.println("\njButton2_actionPerformed(ActionEvent e) called.");
              // TODO: Add any handling code here
         // TODO: Add any method code to meet your needs in the following area
    //============================= Testing ================================//
    //=                                                                    =//
    //= The following main method is just for testing this class you built.=//
    //= After testing,you may simply delete it.                            =//
    //======================================================================//
         public static void main(String[] args)
              JFrame.setDefaultLookAndFeelDecorated(true);
              JDialog.setDefaultLookAndFeelDecorated(true);
              try
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              catch (Exception ex)
                   System.out.println("Failed loading L&F: ");
                   System.out.println(ex);
              new BET();
    //= End of Testing =
    This is my code.. the problem is that when i use sdk 1.3 everything is fine... I tried to use 1.4 and now 5 and I have a problem with the appearance of buttons... I have some comments in my code. is just a form with some textfields and labels and the 2 buttons!
    thx in advance

  • JMenu dismissal action in WindowsLookAndFeel changed for 1.4.1_02 ?

    Hi all,
    It seems to me that the way menus are 'dismissed' in WindowsLookAndFeel has changed in the 1.4.1_02 release. The example program included in this post, when run on 1.3.1_06 (in WindowsLookAndFeel mode) keeps the menu visible until the selected action completes (same as for metal/default L & F modes). However, when run on a 1.4.1_02 system, while the default and metal L & F actions are unchanged, when using WindowsLookAndFeel the menu disappears immediately after the menu item is selected, and leaves an 'empty' rectangle behind! Seems to me that this action change is a bug, but I am hoping that someone might be able to explain what is going on. I could perhaps live with this if the background under the dismissed menu was repainted as part of the dismissal action - but I am unable to make this happen! Again, any insight from others would be most welcome! I am sure this worked with 1.4.1_01, but cannot test this at present.
    dave
    ------ start test code ------
    * Test menu dismissal interval on different JDK versions.
    *'WindowsLookAndFeel' appears to act very differently on 1.4.1_02
    * compared to earlier versions.
    * Menus seem to be dismissed immediately. Only an issue
    * with 'WindowsLookAndFeel' ??
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class MenuTest extends JFrame implements ActionListener
    JMenuBar menuBar;
    public MenuTest()
    super("Menu Test");
    try
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    //UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.MetalLookAndFeel");
    catch (Exception e)
    // Log any error to stdout, then continue
    System.out.println("Error setting Java 'Look & Feel'...");
    //Create the menu bar.
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    JMenu menu = new JMenu("A Menu");
    menuBar.add(menu);
    JMenuItem menuItem = new JMenuItem("Invoke 3 second action");
    menuItem.addActionListener(this);
    menu.add(menuItem);
    public void actionPerformed(ActionEvent event)
    SwingUtilities.invokeLater(new Runnable()
    public void run()
    try
    Thread.sleep(3000);
    } catch (Exception e) { }
    public static void main(String[] args)
    MenuTest mt = new MenuTest();
    mt.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    mt.addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent event)
    System.exit(0);
    // Construct the GUI
    mt.getContentPane().setLayout(new BorderLayout());
    mt.getContentPane().setBackground(Color.red);
    mt.pack();
    // Set form size & location!
    mt.setBounds(new Rectangle(50, 50, 500, 400));
    mt.setVisible(true);
    ------ end test code --------

    I have since determined that the problem is in FileSystemView.getSystemIcon, which returns a garbage icon on my system.

  • Problem in adding JComboBox in JTable

    Hi,
    I was trying to put some comboxes in a jtable. The problem is I am not able to add combo boxes in the 1st and 2nd column. But its adding from the 3rd column. What can be wrong in the following code?
    import javax.swing.DefaultCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import javax.swing.*;
    * TableRenderDemo is just like TableDemo, except that it
    * explicitly initializes column sizes and it uses a combo box
    * as an editor for the Sport column.
    public class TableRenderDemo1 extends JPanel {
        private boolean DEBUG = true;
            DefaultTableCellRenderer renderer =  new DefaultTableCellRenderer();
        public TableRenderDemo1() {
            //super(new GridLayout(1,0));
            JTable table = new JTable(new MyTableModel());
            table.setPreferredScrollableViewportSize(new Dimension(500, 250));
            //Create the scroll pane and add the table to it.
            JScrollPane scrollPane = new JScrollPane(table);
            //Set up column sizes.
            initColumnSizes(table);
            //Fiddle with the Sport column's cell editors/renderers.
            setUpNameColumn(table, table.getColumnModel().getColumn(3));
            //Fiddle with the Sport column's cell editors/renderers.
            setUpSportColumn(table, table.getColumnModel().getColumn(4));
            //Add the scroll pane to this panel.
            add(scrollPane);
            String strPlaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
            try {
                    UIManager.setLookAndFeel(strPlaf);
                    SwingUtilities.updateComponentTreeUI(scrollPane);
            } catch(Exception e) {
                    e.printStackTrace();
         * This method picks good column sizes.
         * If all column heads are wider than the column's cells'
         * contents, then you can just use column.sizeWidthToFit().
        private void initColumnSizes(JTable table) {
            MyTableModel model = (MyTableModel)table.getModel();
            TableColumn column = null;
            Component comp = null;
            int headerWidth = 0;
            int cellWidth = 0;
            Object[] longValues = model.longValues;
            TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer();
            for (int i = 0; i < 5; i++) {
                column = table.getColumnModel().getColumn(i);
                comp = headerRenderer.getTableCellRendererComponent(
                                     null, column.getHeaderValue(),
                                     false, false, 0, 0);
                headerWidth = comp.getPreferredSize().width;
                comp = table.getDefaultRenderer(model.getColumnClass(i)).
                                 getTableCellRendererComponent(
                                     table, longValues,
    false, false, 0, i);
    cellWidth = comp.getPreferredSize().width;
    if (DEBUG) {
    System.out.println("Initializing width of column "
    + i + ". "
    + "headerWidth = " + headerWidth
    + "; cellWidth = " + cellWidth);
    //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
    column.setPreferredWidth(Math.max(headerWidth, cellWidth));
    public void setUpSportColumn(JTable table, TableColumn sportColumn) {
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Snowboarding");
    comboBox.addItem("Rowing");
    comboBox.addItem("Knitting");
    comboBox.addItem("Speed reading");
    comboBox.addItem("Pool");
    comboBox.addItem("None of the above");
    comboBox.setVisible(true);
    sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    renderer.setToolTipText("Click for combo box");
    sportColumn.setCellRenderer(renderer);
    public void setUpNameColumn(JTable table, TableColumn nameColumn) {
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("One");
    comboBox.addItem("Two");
    comboBox.addItem("Three");
    comboBox.addItem("Four");
    comboBox.addItem("Five");
    comboBox.setVisible(true);
    nameColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    renderer.setToolTipText("Click for combo box");
    nameColumn.setCellRenderer(renderer);
    class MyTableModel extends AbstractTableModel {
    private String[] columnNames = {"First Name",
    "Last Name",
    "Sport",
    "# of Years",
    "Vegetarian"};
    private Object[][] data = {
    {"Mary", "Saikat", "Snowboarding", new Integer(5), new Boolean(false)},
    {"Alison", "Srinath", "Rowing", new Integer(3), new Boolean(true)},
    {"Kathy", "Sheela", "Knitting", new Integer(2), new Boolean(false)},
    {"John", "Yashwant", "Something", new Integer(5), new Boolean(true)},
    {"Harry", "Jay", "Playing", new Integer(1), new Boolean(true)},
    public final Object[] longValues = {"Sharon", "Campione",
    "None of the above",
    new Integer(20), Boolean.TRUE};
    public int getColumnCount() {
    return columnNames.length;
    public int getRowCount() {
    return data.length;
    public String getColumnName(int col) {
    return columnNames[col];
    public Object getValueAt(int row, int col) {
    return data[row][col];
    * JTable uses this method to determine the default renderer/
    * editor for each cell. If we didn't implement this method,
    * then the last column would contain text ("true"/"false"),
    * rather than a check box.
    public Class getColumnClass(int c) {
    return getValueAt(0, c).getClass();
    * Don't need to implement this method unless your table's
    * editable.
    public boolean isCellEditable(int row, int col) {
    //Note that the data/cell address is constant,
    //no matter where the cell appears onscreen.
    if (col < 2) {
    return false;
    } else {
    return true;
    * Don't need to implement this method unless your table's
    * data can change.
    public void setValueAt(Object value, int row, int col) {
    if (DEBUG) {
    System.out.println("Setting value at " + row + "," + col
    + " to " + value
    + " (an instance of "
    + value.getClass() + ")");
    data[row][col] = value;
    fireTableCellUpdated(row, col);
    if (DEBUG) {
    System.out.println("New value of data:");
    printDebugData();
    private void printDebugData() {
    int numRows = getRowCount();
    int numCols = getColumnCount();
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + data[i][j]);
    System.out.println();
    System.out.println("--------------------------");
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("TableRenderDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create and set up the content pane.
    TableRenderDemo1 newContentPane = new TableRenderDemo1();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    Thanks in advance.

    First, I don't see where you are tying to set the combo box on the first two columns. I only see it for the 3 and 4.
    Also why are you putting combo boxes in columns that are not editable:
            public boolean isCellEditable(int row, int col) {
                //Note that the data/cell address is constant,
                //no matter where the cell appears onscreen.
                if (col < 2) {
                    return false;
                } else {
                    return true;
            }

  • Problem in LookAndFeel(..JTree..)

    Hi All,
    i have a small problem in LookAndFeel for my Tree. in our project we are using JDK1.1.7B and Swing1.0..It is a client requirement..Is it possible to cretae my tree like windows Explorer..i am not geting tree structure..just i am geting bullets for tree and subtree , I am not geting link to leaf nodes from subtree and link from main leafs to main root...why..i used
    public static String windowsUI = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
    try {
    UIManager.setLookAndFeel(windowsUI);
    UIDefaults def = UIManager.getDefaults();
    for (Enumeration e = def.keys(); e.hasMoreElements();)
    { String key = (String)e.nextElement();
    System.out.println(key+ ":"+def.get(key));
    }catch (Exception ex)
    System.out.println(ex);
    ..........and i tried this also
    try{
    UIManager.setInstalledLookAndFeels(UIManager.getInstalledLookAndFeels());
    }catch(Exception e){System.out.println("Exception "+e);}
    but i am geting exception like this
    Exception occurred during event dispatching:
    java.lang.NoSuchMethodError: com.sun.java.swing.plaf.windows.WindowsTreeUI$Expan
    dedIcon: method createExpandedIcon()Lcom/sun/java/swing/Icon; not found
    at
    at com.sun.java.swing.UIDefaults.get(Compiled Code)
    at com.sun.java.swing.MultiUIDefaults.get(Compiled Code)
    at PopLayersCompHashAllTree.popupLayers(Compiled Code)
    at PopLayersCompHashAllTree.<init>(PopLayersCompHashAllTree.java:38)
    at MapSketchDelAll.actionPerformed(MapSketchDelAll.java:217)
    at com.sun.java.swing.AbstractButton.fireActionPerformed(Compiled Code)
    at com.sun.java.swing.AbstractButton$ForwardActionEvents.actionPerformed
    (AbstractButton.java:924)
    at com.sun.java.swing.DefaultButtonModel.fireActionPerformed(Compiled Co
    de)
    at com.sun.java.swing.DefaultButtonModel.setPressed(DefaultButtonModel.j
    ava:230)
    at com.sun.java.swing.plaf.basic.BasicButtonListener.mouseReleased(Basic
    ButtonListener.java:191)
    at java.awt.Component.processMouseEvent(Component.java:2354)
    at java.awt.Component.processEvent(Compiled Code)
    at java.awt.Container.processEvent(Compiled Code)
    at java.awt.Component.dispatchEventImpl(Compiled Code)
    at java.awt.Container.dispatchEventImpl(Compiled Code)
    at java.awt.Component.dispatchEvent(Compiled Code)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Compiled Code)
    at java.awt.LightweightDispatcher.processMouseEvent(Compiled Code)
    at java.awt.LightweightDispatcher.dispatchEvent(Compiled Code)
    at java.awt.Container.dispatchEventImpl(Compiled Code)
    at java.awt.Window.dispatchEventImpl(Compiled Code)
    at java.awt.Component.dispatchEvent(Compiled Code)
    at java.awt.EventDispatchThread.run(Compiled Code)
    Thanks in Advance,
    Regards
    Akula

    hi sir ,
    thaks for u'r suggession.Its working fine but the
    properties of the previous tree were not working
    after setModel() property .like action at leaf node
    is not working,I'm sorry but I don't understand. I think you are saying that the problem is solved but I can read it to mean that you still have a problem.
    If you still have a problem then please post some code (using the [code] tags of course).

  • Problem in LookAndFeel

    Hi All,
    i have a small problem in LookAndFeel for my Tree. in our project we are using JDK1.1.7B and Swing1.0..It is a client requirement..Is it possible to cretae my tree like windows Explorer..i am not geting tree structure..just i am geting bullets for tree and subtree , I am not geting link to leaf nodes from subtree and link from main leafs to main root...why..i used
    public static String windowsUI = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
    try {     
    UIManager.setLookAndFeel(windowsUI);     
    UIDefaults def = UIManager.getDefaults();     
    for (Enumeration e = def.keys(); e.hasMoreElements();)
    {  String key = (String)e.nextElement();     
    System.out.println(key+ ":"+def.get(key));
    }catch (Exception ex)
    System.out.println(ex);     
    ..........and i tried this also
    try{
    UIManager.setInstalledLookAndFeels(UIManager.getInstalledLookAndFeels());
              }catch(Exception e){System.out.println("Exception "+e);}
    but i am geting exception like this
    Exception occurred during event dispatching:
    java.lang.NoSuchMethodError: com.sun.java.swing.plaf.windows.WindowsTreeUI$Expan
    dedIcon: method createExpandedIcon()Lcom/sun/java/swing/Icon; not found
    at
    at com.sun.java.swing.UIDefaults.get(Compiled Code)
    at com.sun.java.swing.MultiUIDefaults.get(Compiled Code)
    at PopLayersCompHashAllTree.popupLayers(Compiled Code)
    at PopLayersCompHashAllTree.<init>(PopLayersCompHashAllTree.java:38)
    at MapSketchDelAll.actionPerformed(MapSketchDelAll.java:217)
    at com.sun.java.swing.AbstractButton.fireActionPerformed(Compiled Code)
    at com.sun.java.swing.AbstractButton$ForwardActionEvents.actionPerformed
    (AbstractButton.java:924)
    at com.sun.java.swing.DefaultButtonModel.fireActionPerformed(Compiled Co
    de)
    at com.sun.java.swing.DefaultButtonModel.setPressed(DefaultButtonModel.j
    ava:230)
    at com.sun.java.swing.plaf.basic.BasicButtonListener.mouseReleased(Basic
    ButtonListener.java:191)
    at java.awt.Component.processMouseEvent(Component.java:2354)
    at java.awt.Component.processEvent(Compiled Code)
    at java.awt.Container.processEvent(Compiled Code)
    at java.awt.Component.dispatchEventImpl(Compiled Code)
    at java.awt.Container.dispatchEventImpl(Compiled Code)
    at java.awt.Component.dispatchEvent(Compiled Code)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Compiled Code)
    at java.awt.LightweightDispatcher.processMouseEvent(Compiled Code)
    at java.awt.LightweightDispatcher.dispatchEvent(Compiled Code)
    at java.awt.Container.dispatchEventImpl(Compiled Code)
    at java.awt.Window.dispatchEventImpl(Compiled Code)
    at java.awt.Component.dispatchEvent(Compiled Code)
    at java.awt.EventDispatchThread.run(Compiled Code)

    you are probably setting the LookAndFeel in the wrong spot in your code. You should set it every time your window reopens instead of just in the initialization.

  • Highlighting problems

    Hi,
    i have created a specific JTextField that, among other things, only can take in numbers. To do this I have modified the Document of the textfield.
    My problem is that the user can toggle between two different textfields using a combo box. One textfield of this kind and one standard JTextField. When the user toggles the focus should be on the text field, and if there is text in the textfield it should be highlighted. This works fine for the standard JTextField using requestFocus() on the textfield, and a FocusListener that does a selectAll() when the text field recieves focus. But my "enhanced" textfield gets a null pointer exception when the selectAll() occurs. Any ideas?
    The TextFields new Document
    protected Document createDefaultModel() {
    return new FaTkTaxNrDocument();
    protected class FaTkTaxNrDocument extends PlainDocument
    public void insertString(int offs, String str, AttributeSet a)
    throws BadLocationException
    char[] source = str.toCharArray();
    int size = source.length;
    char[] result = new char[size];
    int j = 0;
    boolean dashSet = false;
    // Ska endast f� plats 7 tecken
    if(this.getLength() > 7) {
    return;
    for (int i = 0; i < result.length; i++) {
    if (Character.isDigit(source)) {
    result[j++] = source[i];
    if (offs+i == 6) {
    dashSet = true;
    else if (offs == 6 && Character.isSpaceChar(source[i])) {
    result[j++] = '-';
    else {
    // System.err.println("insertString: " + source[i]);
    if(dashSet) {
    super.insertString(offs, new String(result, 0, j), a);
    super.insertString(offs, "-", null);
    else
    super.insertString(offs, new String(result, 0, j), a);
    The focus listener
    public class FaTkInputListener implements FocusListener
    public void focusGained(FocusEvent arg0)
         selectAll();
    The null pointer exception
    Exception occurred during event dispatching:
    java.lang.NullPointerException
         at javax.swing.plaf.basic.BasicTextUI.damageRange(Unknown Source)
         at javax.swing.plaf.basic.BasicTextUI.damageRange(Unknown Source)
         at javax.swing.text.DefaultHighlighter.addHighlight(Unknown Source)
         at javax.swing.text.DefaultCaret.moveDot(Unknown Source)
         at javax.swing.text.DefaultCaret.moveDot(Unknown Source)
         at javax.swing.text.JTextComponent.moveCaretPosition(Unknown Source)
         at javax.swing.text.JTextComponent.selectAll(Unknown Source)
         at se.rsv.fa.tk.client.view.FaTkInputField$FaTkInputListener.focusGained(FaTkInputField.java:124)
         at java.awt.AWTEventMulticaster.focusGained(Unknown Source)
         at java.awt.Component.processFocusEvent(Unknown Source)
         at javax.swing.JComponent.processFocusEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.setFocusRequest(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Container.proxyRequestFocus(Unknown Source)
         at java.awt.Component.requestFocus(Unknown Source)
         at javax.swing.JComponent.grabFocus(Unknown Source)
         at javax.swing.JComponent.requestFocus(Unknown Source)
         at se.rsv.fa.tk.client.application.view.FaTkSearchBar.updateData(FaTkSearchBar.java:161)
         at se.rsv.fa.tk.client.control.FaTkModelListener.modelChanged(FaTkModelListener.java:54)
         at se.rsv.fa.tk.client.model.FaTkModel.fireChangedEvent(FaTkModel.java:78)
         at se.rsv.fa.tk.client.model.FaTkModel.setData(FaTkModel.java:110)
         at se.rsv.fa.tk.client.model.FaTkModel.runUpdate(FaTkModel.java:57)
         at se.rsv.fa.tk.client.view.FaTkSelectBox.fireDataEvent(FaTkSelectBox.java:89)
    at se.rsv.fa.tk.client.view.FaTkSelectBox$FaTkSelectionListener.itemStateChanged(FaTkSelectBox.java:109)
         at javax.swing.JComboBox.fireItemStateChanged(Unknown Source)
         at javax.swing.JComboBox.selectedItemChanged(Unknown Source)
         at javax.swing.JComboBox.contentsChanged(Unknown Source)
         at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
         at javax.swing.DefaultComboBoxModel.setSelectedItem(Unknown Source)
         at javax.swing.JComboBox.setSelectedItem(Unknown Source)
         at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
         at javax.swing.plaf.basic.BasicComboBoxUI.selectPreviousPossibleValue(Unknown Source)
    at com.sun.java.swing.plaf.windows.WindowsComboBoxUI.selectPreviousPossibleValue(Unknown Source)
         at com.sun.java.swing.plaf.windows.WindowsComboBoxUI$UpAction.actionPerformed(Unknown Source)
         at javax.swing.SwingUtilities.notifyAction(Unknown Source)
         at javax.swing.JComponent.processKeyBinding(Unknown Source)
         at javax.swing.JComponent.processKeyBindings(Unknown Source)
         at javax.swing.JComponent.processKeyEvent(Unknown Source)
         at javax.swing.JComboBox.processKeyEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processKeyEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Window.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)

    Hi everyone, I have changed nick from mbr1799 to Mr. Brodd
    Ok guys, here is a program that reproduces the exception.
    Copy, compile and run!
    import java.awt.*;
    import java.awt.datatransfer.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ClipTest extends JFrame
    implements ActionListener, KeyListener, FocusListener
    JTextField tf = new JTextField(20);
    JTextField tf2 = new JTextField(20);
    JComboBox cb = null;
    JComboBox cb2 = null;
    JButton b = null;
    JLabel l1 = new JLabel("Kommun");
    JLabel l2 = new JLabel("Taxenhet");
    Box toolBox = new Box(BoxLayout.X_AXIS);
    String keys = null;
    public ClipTest() {
    String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
    try {
    UIManager.setLookAndFeel(lookAndFeel);
    catch (ClassNotFoundException e) {
    System.out.println("Couldn't find class for specified look and feel:" + lookAndFeel);
    System.out.println("Did you include the L&F library in the class path?");
    System.out.println("Using the default look and feel.");
    catch (UnsupportedLookAndFeelException e) {
    System.out.println("Can't use the specified look and feel ("+ lookAndFeel + ") on this platform.");
    System.out.println("Using the default look and feel.");
    catch (Exception e) {
    System.out.println("Couldn't get specified look and feel ("+ lookAndFeel+ "), for some reason.");
    System.out.println("Using the default look and feel.");
    //e.printStackTrace();
    init();
    public static void main(String[] args) {
    ClipTest ct = new ClipTest();
    public void init() {
    button.setBackground(Color.blue);
    Box topBox = new Box(BoxLayout.Y_AXIS);
    String[] listExamples = {"kommun", "taxenhet"};
    cb2 = new JComboBox(listExamples);
    cb2.addActionListener(this);
    tf.addFocusListener(this);
    tf2.addFocusListener(this);
    fixBox();
    this.getContentPane().add(toolBox);
    this.pack();
    setVisible(true);
    private void fixBox()
    toolBox.add(Box.createHorizontalStrut(5));
    toolBox.add(cb2);
    toolBox.add(Box.createHorizontalStrut(5));
    toolBox.add(l1);
    toolBox.add(tf);
    toolBox.add(Box.createHorizontalStrut(5));
    toolBox.add(l2);
    toolBox.add(tf2);
    l2.setVisible(false);
    tf2.setVisible(false);
    private void fixBoxKommun() {
    l1.setVisible(true);
    tf.setVisible(true);
    l2.setVisible(false);
    tf2.setVisible(false);
    tf.requestFocus();
    private void fixBoxTax() {
    l1.setVisible(false);
    tf.setVisible(false);
    l2.setVisible(true);
    tf2.setVisible(true);
    tf2.requestFocus();
    public void actionPerformed(ActionEvent e) {
    System.out.println("Action " + e.toString());
    String selected = (String)cb2.getSelectedItem();
    if(selected.equals("kommun"))
    fixBoxKommun();
    else if(selected.equals("taxenhet"))
    fixBoxTax();
    else
    System.out.println("Huh??");
    public void keyPressed(KeyEvent ke) {
    public void keyReleased(KeyEvent ke) {
    public void keyTyped(KeyEvent ke) {
    public void lostOwnership(Clipboard cb, Transferable tr)
    public void focusGained(FocusEvent fe) {
    if(tf.isVisible())
    tf.selectAll();
    else if(tf2.isVisible())
    tf2.selectAll();
    public void focusLost(FocusEvent fe) {
    }

  • Keyboard problems with joptionpane.ShowConfirm

    hello,
    I am using show confirm dialog and there is a yes and no button with it.
    I want the software to exit when the user clicks yes button.
    the code works fine when the user uses mouse. but when I use the enter key on yes or no button, the application exits in both the cases.
    further more if I perform the same action with the space bar on the keyboard it still works fine and when I hit space bar on the no button the application stays. but with enter key the application doesn't seam to take the right yes/ no value in the integer.
    what's the problem
    and how do I correct it.
    thanks
    Krishnakant.

    import javax.swing.*;
    class Testing
       public Testing()
          try{UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");}
          catch(Exception e){e.printStackTrace();}
          int btn = JOptionPane.showConfirmDialog(null,"tab to a button, then press [ENTER]",
                                                             "",JOptionPane.YES_NO_OPTION,-1);
          String selection = "Escape (or 'x') selected";
          if(btn == 0) selection = "Selection = 'Yes'";
          else if(btn == 1)  selection = "Selection = 'No'";
          JOptionPane.showMessageDialog(null,selection);
          System.exit(0);
      public static void main(String[] args){new Testing();}
    }

Maybe you are looking for