Checkboxgroup setSelected() problem

Hi,
I have a number items read from a .txt file into a checkboxGroup. I have problem in selecting some of them automatically. Please help me in setSelected() function code:
//get selected automatically
         try {                   
             int numOfLines2 = 0;
            int count2=0;
            String theLine2 = null;
            FileReader fr4 = new FileReader("C:/CreatorProjects/Npad_PAIRS_NLP.prs");
            BufferedReader br4 = new BufferedReader(fr4);
            while ((theLine2 = br4.readLine()) != null) {
                numOfLines2++;
            fr4.close();          // close the file.
            br4.close();          // close the buffer
            FileReader fr5 = new FileReader("C:/CreatorProjects/Npad_PAIRS_NLP.prs");
            BufferedReader br5 = new BufferedReader(fr5);
            listPatientdata = new com.sun.rave.web.ui.model.Option[numOfLines2];
            while ((theLine2 = br5.readLine()) != null || count2 <= numOfLines2) {
                listPatientdata[count2] = new Option(theLine2, theLine2);
                if(count2<=ptftrs)      //ptftrs is predefined integer
                    checkboxGroup1.setSelected(theLine2);
                count2++;
            } catch(Exception e) {
            e.printStackTrace();    
   }I have no problem in using the code if I want all boxes unselected initially.
thanks in advance.
dr.am.mohan rao

while ((theLine2 = br5.readLine()) != null || count2 <= numOfLines2) {
listPatientdata[count2] = new Option(theLine2, theLine2);
if(count2<=ptftrs)      //ptftrs is predefined integer
checkboxGroup1.setSelected(theLine2);
count2++;         
} catch(Exception e) {
e.printStackTrace();     My guess is to call setSelected after adding all options to check box group. Try something like:
String valueToSelect = null;
while((theLine2 = br5.readLine()) != null || count <= numOfLines2) {
listPatientdata[count2] = new Option(theLine2, theLine2);
if(count2 <= ptftrs)
valueToSelect = theLine2;
count2++;
checkboxGroup1.setSelected(valueToSelect);best regards
Grzegorz

Similar Messages

  • JRadioButton setSelected problem

    Hi,
    I am trying to change the status of my JRadio buttons to false, but they do not get updated. One of them still remains selected.
    Any ideas?
    radioButton1.setSelected(false);
    radioButton2.setSelected(false);

    devboris wrote:
    I am trying to change the status of my JRadio buttons to false, but they do not get updated. One of them still remains selected.
    Any ideas?
    radioButton1.setSelected(false);
    radioButton2.setSelected(false);
    This should be posted in the Swing forum, not the Java 2D forum.
    Regardless, if you are using Java 1.6, then I recommend that you call clearSelection on the ButtonGroup object. If you are not using Java 1.6, then you can always add to your button group another invisible jradiobutton and set its selected property to true.

  • Problem with setSelection and components

    Hi! I have a problem with setSelection function when there is
    any component on the stage or in the library. Just look on the
    sample
    here The first
    button sets focus and sets selection, the second one removes focus.
    It works good, but add any component to break it. Is there any
    other way to unset focus? Maybe this is the problem... Any help?
    BTW Sorry for my english :)

    Selection.setFocus(component) removes current
    selection

  • Problem with Checkboxgroup

    Hi!
    I unfortunately have a problem with checkboxgroups. For the action onToggle I mapped the Parameters in wdDoModifyView() the following:
    if (firstTime) {
    // Get references to all checkboxgroups
    IWDCheckBoxGroup cg1 = (IWDCheckBoxGroup) view.getElement("CheckBoxGroup1");
    // Link the client-side event parameter 'index' to the server-side action parameter 'cgindex'
    cg1.mappingOfOnToggle().addSourceMapping("index", "cgindex");
    cg1.mappingOfOnToggle().addSourceMapping("checked", "cgchecked");
    // Hardcode the checkboxgroup name for each action parameter         
    cg1.mappingOfOnToggle().addParameter("cgname", cg1.getId());
    In my onToggle action, how can I find out now whether the checkbox at index cgindex is checked??
    Would be great if you can help me with that.
    Bye,
    Timo

    Sorry for my poor English ><
    Step1. Create a Value Node under Root Element
           Name : CheckBoxGroup
           cardinality : 0 .. n
           selection : 0 .. n
            Context
               |--- CheckBoxGroup
    Step2. Create a context element under CheckBoxGroup
           Name : CKItem ( type : String )
            Context
               |--- CheckBoxGroup
                          |---- CKItem
    Step3. Put an CheckBoxGroup UI object on Layout .
           Property colcount : 3 ( for example )
           texts : CheckBoxGroup.CKItem
    Step4. Create a new Action named "ChkGroupToggled"
           with two parameter
           1. cgIndex ( int )
           2. cgChecked ( boolean )
    Step5. Code implementation
      public static void wdDoModifyView(IPrivateTest941124View wdThis, IPrivateTest941124View.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
        //@@begin wdDoModifyView
        try{
              if (firstTime) {
                IWDCheckBoxGroup cg1 = (IWDCheckBoxGroup) view.getElement("CheckBoxGroup1") ;
                cg1.mappingOfOnToggle().addSourceMapping("index", "cgIndex") ;
                cg1.mappingOfOnToggle().addSourceMapping("checked", "cgChecked") ;
        catch( Exception e ){
        //@@end
    Step6. Code implementation
      public void onActionChkGroupToggled(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, int cgIndex, boolean cgChecked )
        //@@begin onActionChkGroupToggled(ServerEvent)
        try{
              // Context Element "Info" is just for debug prupose only
              wdContext.currentContextElement().setInfo( cgIndex + " : " + cgChecked ) ;
        catch( Exception e ){
        //@@end
    Step7. Add an UI object ( ex : TextEdit ) on Layout and bind the "value" parperty with context element "Info"
    Step8. Bind action with onToggle Event in the UI element created in Step3.
    Step9. Deploy and Run your webdynpro

  • Problem displaying CheckboxGroup on JFrame

    I was recently assigned the task of creating exams. I am trying to create a CheckboxGroup in a class that was passed the Graphics2D tool. This code compiles with no errors when I call it's method:
    setLayout(new GridLayout(1, 5));
              CheckboxGroup cbg = new CheckboxGroup();
              add(new Checkbox("Never", cbg, false));
              add(new Checkbox("Almost Never", cbg, false));
              add(new Checkbox("Sometimes", cbg, false));
              add(new Checkbox("Almost All The Time", cbg, false));
              add(new Checkbox("All The Time", cbg, false));
    but nothing displays on my JFrame, I tried to draw it with this line(g2 is my Graphics2D tool):
    g2.draw(cbg);
    but I get an error when compiling that says draw doesn't work. Am I totally off-track with this or is there a simple Graphics2D method that I use to draw this CheckboxGroup?

    hiwa: Thanks for the tip, I won't mix those libraries anymore
    pete: Here is all of my code so far sorry it's sloppy, I'm just getting back into coding after one semester of Intro to Computer Science using Java almost a year ago::/*this class has main function**************************************************/
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    public class PDS_Questionnaire
         public static void main(String[] args)
              //declare JFrame window dimensions
              int WIDTH = 500;
              int HEIGHT = 400;
              //create JFrame
              JFrame frame = new JFrame();
              frame.setSize(HEIGHT, WIDTH);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //create object of painter class to install onto frame
              ScoreCard survey = new ScoreCard();
              //add object to frame and set visible
              frame.add(survey);
              frame.setVisible(true);
    /*********************end of class***************************************/
    /****************************new class**********************************/
    //this class is the JFrame painter, it initiates the Graphics2D class then passes the
    //Graphics object to PDS_Scorer so that the PDS_Scorer class can draw on the patientsCard
    import javax.swing.JComponent;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    public class ScoreCard extends JComponent
         public ScoreCard()
         public void paintComponent(Graphics g)
              //recover Graphics2D
              Graphics2D g2 = (Graphics2D) g;
                    //create another class and pass the Graphics2D tool
              PDS_Scorer patientsCard = new PDS_Scorer(g2);
                    //call method to draw the check boxes
              patientsCard.drawCheckBoxes();
    /*********************end of class***************************************/
    /****************************new class**********************************/
    import javax.swing.JComponent;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.GridLayout;
    import java.awt.Checkbox;
    import java.awt.CheckboxGroup;
    public class PDS_Scorer extends JComponent
         public PDS_Scorer(Graphics2D gTwo)
              g2 = gTwo;
         public void partA_Scorer()
         public void partB_Scorer()
         public void partC_Scorer()
         public void partD_Scorer()
         public void partE_Scorer()
         public void partF_Scorer()
         public void drawCheckBoxes()
    //           draw3DRect(int x, int y, int width, int height, boolean raised)
    //      Draws a 3-D highlighted outline of the specified rectangle.
              g2.draw3DRect(10, 10, 10, 10, true);   //this works
              setLayout(new GridLayout(1, 5));
              CheckboxGroup cbg = new CheckboxGroup();
              add(new Checkbox("Never", cbg, false));
              add(new Checkbox("Almost Never", cbg, false));
              add(new Checkbox("Sometimes", cbg, false));
              add(new Checkbox("Almost All The Time", cbg, false));
              add(new Checkbox("All The Time", cbg, false));
            //g2.drawString("One Lazy Fox", 22.5, 55.5);
         private Graphics2D g2;
    }

  • Can some one help me with this problem with my frame???

    i have gt a veri strange problem with my program,that is teh graphic changes only when i resize the the frame,if i dun resize,it will remain the same.However what i intended is that when i click on the radio button,it will change immediately to the respective pages.A simple version of my code is below,can someone helpl me solve it??(there is 3 different class)
    import java.awt.event.*;
    import javax.swing.*;
    public class MainPg extends JFrame implements ActionListener{
         private javax.swing.JPanel jContentPane = null;
         private javax.swing.JPanel buttons = null;
         private javax.swing.JRadioButton one = null;
         private javax.swing.JRadioButton two = null;
         private javax.swing.JPanel change = null;
         public MainPg() {
              super();
              initialize();
         private void initialize() {
              this.setSize(300, 200);
              this.setContentPane(getJContentPane());
              this.setName("mainClass");
              this.setVisible(true);
         private javax.swing.JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new javax.swing.JPanel();
                   jContentPane.setLayout(new java.awt.BorderLayout());
                   jContentPane.add(getButtons(), java.awt.BorderLayout.WEST);
                   jContentPane.add(getChange(), java.awt.BorderLayout.CENTER);
              return jContentPane;
         private javax.swing.JPanel getButtons() {
              if(buttons == null) {
                   buttons = new javax.swing.JPanel();
                   java.awt.GridLayout layGridLayout1 = new java.awt.GridLayout();
                   layGridLayout1.setRows(2);
                   layGridLayout1.setColumns(1);
                   ButtonGroup group=new ButtonGroup();
                   group.add(getOne());
                   group.add(getTwo());
                   buttons.setLayout(layGridLayout1);
                   buttons.add(getOne(), null);
                   buttons.add(getTwo(), null);
              return buttons;
         private javax.swing.JRadioButton getOne() {
              if(one == null) {
                   one = new javax.swing.JRadioButton();
                   one.setText("One");
                   one.setSelected(true);
                   one.addActionListener(this);
                   one.setActionCommand("one");
              return one;
         private javax.swing.JRadioButton getTwo() {
              if(two == null) {
                   two = new javax.swing.JRadioButton();
                   two.setText("Two");
                   two.addActionListener(this);
                   two.setActionCommand("two");
              return two;
         private javax.swing.JPanel getChange() {
              if(change == null) {
                   change = new javax.swing.JPanel();
              change.add(new One());
              return change;
         public static void main(String[] args){
              new MainPg();
         public void actionPerformed(ActionEvent e) {
              change.removeAll();
              if("one".equals(e.getActionCommand())){
                   change.add(new One());
              else{
                   change.add(new Two());
              change.repaint();
    import javax.swing.*;
    public class One extends JPanel {
         private javax.swing.JPanel jPanel = null;
         private javax.swing.JLabel jLabel = null;
         private javax.swing.JPanel jPanel1 = null;
         private javax.swing.JLabel jLabel1 = null;
         private javax.swing.JLabel jLabel2 = null;
         public One() {
              super();
              initialize();
         * This method initializes this
         * @return void
         private void initialize() {
              this.setLayout(new java.awt.BorderLayout());
              this.add(getJPanel(), java.awt.BorderLayout.NORTH);
              this.add(getJPanel1(), java.awt.BorderLayout.WEST);
              this.setSize(300, 200);
         * This method initializes jPanel
         * @return javax.swing.JPanel
         private javax.swing.JPanel getJPanel() {
              if(jPanel == null) {
                   jPanel = new javax.swing.JPanel();
                   jPanel.add(getJLabel(), null);
              return jPanel;
         * This method initializes jLabel
         * @return javax.swing.JLabel
         private javax.swing.JLabel getJLabel() {
              if(jLabel == null) {
                   jLabel = new javax.swing.JLabel();
                   jLabel.setText("one");
              return jLabel;
         * This method initializes jPanel1
         * @return javax.swing.JPanel
         private javax.swing.JPanel getJPanel1() {
              if(jPanel1 == null) {
                   jPanel1 = new javax.swing.JPanel();
                   java.awt.GridLayout layGridLayout2 = new java.awt.GridLayout();
                   layGridLayout2.setRows(2);
                   layGridLayout2.setColumns(1);
                   jPanel1.setLayout(layGridLayout2);
                   jPanel1.add(getJLabel2(), null);
                   jPanel1.add(getJLabel1(), null);
              return jPanel1;
         * This method initializes jLabel1
         * @return javax.swing.JLabel
         private javax.swing.JLabel getJLabel1() {
              if(jLabel1 == null) {
                   jLabel1 = new javax.swing.JLabel();
                   jLabel1.setText("one");
              return jLabel1;
         * This method initializes jLabel2
         * @return javax.swing.JLabel
         private javax.swing.JLabel getJLabel2() {
              if(jLabel2 == null) {
                   jLabel2 = new javax.swing.JLabel();
                   jLabel2.setText("one");
              return jLabel2;
    import javax.swing.*;
    public class Two extends JPanel {
         private javax.swing.JLabel jLabel = null;
         public Two() {
              super();
              initialize();
         * This method initializes this
         * @return void
         private void initialize() {
              this.setLayout(new java.awt.FlowLayout());
              this.add(getJLabel(), null);
              this.setSize(300, 200);
         * This method initializes jLabel
         * @return javax.swing.JLabel
         private javax.swing.JLabel getJLabel() {
              if(jLabel == null) {
                   jLabel = new javax.swing.JLabel();
                   jLabel.setText("two");
              return jLabel;
    }

    //change.repaint();
    change.revalidate();

  • JInternalFrame drawing problem.

    Hi gurus
    Please could you help with a java problem that I cant find an answer to over the net:
    I have a JDesktop which contains multiple JInternalFrames. On one JInternalFrame i have attached a JPanel on which to draw on. I have multiple threads (simple ball shapes) that need to be drawn onto the JPanel and have left it up to the indivual threads to draw themselves (as opposed to using paintComponent in the JPanel class). The drawing on the JInternalFrame works perfectly fine.
    The problem arises when the other JInternalFrames are placed on top of each other - the balls are drawn over the top most JInternalFrame. What am i doing wrong? I have attached snippets of the code:
    public class Desktop extends JFrame implements ActionListener
              public Desktop()
                        setTitle("Agent's world");
                        setSize(w,h);
                        setDefaultCloseOperation(EXIT_ON_CLOSE);
                        JDesktopPane desktop = new JDesktopPane();
                        setContentPane(desktop);
                        /************* Agent *************/
                        JInternalFrame agents = new JInternalFrame("Agents War", true, false, true, false);                    
                        agents.reshape(0,0,(int)((w/3)*2),h);
                        Container contentPane = agents.getContentPane();
                        canvas = new AgentPanel(agents);
                        contentPane.add(canvas);
                        /************* Button *************/
                        JPanel buttonPanel = new JPanel();
                        ButtonGroup buttonGroup = new ButtonGroup();
                        JButton start = new JButton("START");
                        start.addActionListener(this);
                        buttonPanel.add(start);
                        contentPane.add(buttonPanel, "North");
                        agents.setVisible(true);
                        desktop.add(agents);
                        //sets focus to other frames within the desktop
                        try
                                  agents.setSelected(true);
                        catch(PropertyVetoException e)
                                  //attempt to refocus was vetoed by a frame
              /** Method to listen for event actions, i.e. button clicks **/
         public void actionPerformed(ActionEvent event)
                   //passes through 'this' to allow access to the getList method
                   Agents agent = new Agents(canvas, this);
                   agent.start();
    public class Agents extends Thread
              public Agents(AgentPanel panel, Desktop desktop)
                        panel =_panel;
                        desktop = _desktop;
                        setDaemon(true);
    /** Moves the agent from a spefic position to a new position **/
              public void move()
                        Graphics g = panel.getGraphics();
                        Graphics2D g2 = (Graphics2D)g;
                        try
                                  //set XOR mode
                                  g.setXORMode(panel.getBackground());
                                  //draw over old
                                  Ellipse2D.Double ballOld = new Ellipse2D.Double(i , j, length, length);
                                  g2.fill(ballOld);     
                                  i++;
                                  j++;
                                  if(flag == true)
                                            //draw new
                                            Ellipse2D.Double ballNew = new Ellipse2D.Double(i , j, length, length);
                                            g2.fill(ballNew);
                                            g2.setPaintMode();
                        finally
                                  g.dispose();
              /** Activates the Thread **/
              public void run()
                   int i = 0;
                   while(!interrupted() && i<100)
                        try
                                       for(i = 0 ; i <100 ; i++)
                                                 //draw ball in old position                                             move();          
                                                 sleep(100);                              
                             catch(InterruptedException e)
    public class AgentPanel extends JPanel
              /** local copy of internal frame */
              private JInternalFrame frame;
              public AgentPanel(JInternalFrame _frame)
                        frame = _frame;
                        setSize(frame.getWidth(), frame.getHeight());
                        setBackground(Color.white);          
              public void paintComponent(Graphics g)
                        super.paintComponent(g);
    Thank you in advance.
    Ravs

    I have the same problem. Seems to be a bug. See:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=231037
    Bummer.

  • Problem in validating menu item

    hi,
    everybody.
    i have created a main window using JInternalFrame. The window has a menu bar in which document menu is used for closing the main window, while employee menu is used for adding new frame for the employee. while the login frame is displayed when the application is executed.
    my problem is that i want to validate that before login employee menu should be disabled, and after login is performed employee menu is enabled.
    the following is my code. please reply me as i am stucked with it.
    thanks in advance.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    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);
              desktop = new JDesktopPane();
              setContentPane(desktop);
              desktop.setBackground(Color.white);
              setJMenuBar(createMenuBar());
              desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
              createLogin();
         public JMenuBar createMenuBar()
              JMenuBar menuBar = new JMenuBar();
              JMenu menu = new JMenu("Document");
              menu.setMnemonic(KeyEvent.VK_D);
              menuBar.add(menu);
              JMenuItem menuItem = new JMenuItem("Quit");
              menuItem.setMnemonic(KeyEvent.VK_Q);
              menuItem.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.ALT_MASK));
              menuItem.setActionCommand("quit");
              menuItem.addActionListener(this);
              menu.add(menuItem);
              JMenu employee = new JMenu("Employee");
              employee.setMnemonic(KeyEvent.VK_E);
              employee.setActionCommand("employee");
              menuBar.add(employee);
              JMenuItem additem = new JMenuItem("Add");
              additem.setMnemonic(KeyEvent.VK_A);
              additem.setActionCommand("add");
              additem.addActionListener(this);
              employee.add(additem);
              return menuBar;
         public void actionPerformed(ActionEvent ae)
              String str = ae.getActionCommand();
              if(str.equals("add"))
                   System.out.println("Employee Form Invoked");
                   createEmployee();
              else if(str.equals("quit"))
                   quit();
         public void createEmployee()
              MyEmployeeFrame employeeframe = new MyEmployeeFrame();
              employeeframe.setVisible(true);
              desktop.add(employeeframe);
              try
                   employeeframe.setSelected(true);
              catch(Exception e)
         public void createLogin()
              MyLogin loginframe = new MyLogin();
              loginframe.setVisible(true);
              desktop.add(loginframe);
              try
                   loginframe.setSelected(true);
              catch(Exception e){}
         public void quit()
              System.exit(0);
         private static void createAndShowGUI()
              JFrame.setDefaultLookAndFeelDecorated(true);
              InternalFrameDemo frame = new InternalFrameDemo();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(800,600);
              frame.setVisible(true);
         public static void main(String a[])
              createAndShowGUI();
    class MyEmployeeFrame extends JInternalFrame implements ActionListener
         JFrame employeeframe;
         JLabel labelfirstname;
         JLabel labellastname;
         JLabel labelage;
         JLabel labeladdress;
         JLabel labelcity;
         JLabel labelstate;
         JTextField textfirstname;
         JTextField textlastname;
         JTextField textage;
         JTextField textaddress;
         JTextField textcity;
         JTextField textstate;
         JButton buttonsave;
         FileOutputStream out;
         PrintStream p;
         String strfirstname,strlastname,strage,straddress,strcity,strstate;
         GridBagLayout gl;
         GridBagConstraints gbc;
         public MyEmployeeFrame()
              super("Employee Details",true,true,true,true);
              setSize(500,400);
              labelfirstname = new JLabel("First Name");
              labellastname = new JLabel("Last Name");
              labelage = new JLabel("Age");
              labeladdress = new JLabel("Address");
              labelcity = new JLabel("City");
              labelstate = new JLabel("State");
              textfirstname = new JTextField(10);
              textlastname = new JTextField(10);
              textage = new JTextField(5);
              textaddress = new JTextField(15);
              textcity = new JTextField(10);
              textstate = new JTextField(10);
              buttonsave = new JButton("Save");
              gl = new GridBagLayout();
              gbc = new GridBagConstraints();
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 3;
              gl.setConstraints(labelfirstname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 3;
              gl.setConstraints(textfirstname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 5;
              gl.setConstraints(labellastname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 5;
              gl.setConstraints(textlastname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 7;
              gl.setConstraints(labelage,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 7;
              gl.setConstraints(textage,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 9;
              gl.setConstraints(labeladdress,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 9;
              gl.setConstraints(textaddress,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 11;
              gl.setConstraints(labelcity,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 11;
              gl.setConstraints(textcity,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 13;
              gl.setConstraints(labelstate,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 13;
              gl.setConstraints(textstate,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 17;
              gl.setConstraints(buttonsave,gbc);
              Container contentpane = getContentPane();
              contentpane.setLayout(gl);
              contentpane.add(labelfirstname);
              contentpane.add(textfirstname);
              contentpane.add(labellastname);
              contentpane.add(textlastname);
              contentpane.add(labelage);
              contentpane.add(textage);
              contentpane.add(labeladdress);
              contentpane.add(textaddress);
              contentpane.add(labelcity);
              contentpane.add(textcity);
              contentpane.add(labelstate);
              contentpane.add(textstate);
              contentpane.add(buttonsave);
              buttonsave.addActionListener(this);
         public void reset()
              textfirstname.setText("");
              textlastname.setText("");
              textage.setText("");
              textaddress.setText("");
              textcity.setText("");
              textstate.setText("");
         public void actionPerformed(ActionEvent ae)
              String str = ae.getActionCommand();
              System.out.println(str);
              if(str.equalsIgnoreCase("Save"))
                 try
                         out = new FileOutputStream("myfile.txt",true);
                         p = new PrintStream( out );
                         strfirstname = textfirstname.getText();
                         strlastname = textlastname.getText();
                         strage = textage.getText();
                         straddress = textaddress.getText();
                         strcity = textcity.getText();
                         strstate = textstate.getText();
                         p.print(strfirstname+"|");
                         p.print(strlastname+"|");
                         p.print(strage+"|");
                         p.print(straddress+"|");
                         p.print(strcity+"|");
                         p.println(strstate);
                         System.out.println("Record Saved");
                         reset();
                         p.close();
                 catch (Exception e)
                         System.err.println ("Error writing to file");
    class MyLogin extends JInternalFrame implements ActionListener
         JFrame loginframe;
         JLabel labelname;
         JLabel labelpassword;
         JTextField textname;
         JPasswordField textpassword;
         JButton okbutton;
         String name = "";
         FileOutputStream out;
         PrintStream p;
         Date date;
         GregorianCalendar gcal;
         GridBagLayout gl;
         GridBagConstraints gbc;
         public MyLogin()
              super("Login",true,true,true,true);
              setSize(400,300);
              gl = new GridBagLayout();
              gbc = new GridBagConstraints();
              labelname = new JLabel("User");
              labelpassword = new JLabel("Password");
              textname = new JTextField("",9);
              textpassword = new JPasswordField(5);
              okbutton = new JButton("OK");
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 5;
              gl.setConstraints(labelname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 2;
              gbc.gridy = 5;
              gl.setConstraints(textname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 10;
              gl.setConstraints(labelpassword,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 2;
              gbc.gridy = 10;
              gl.setConstraints(textpassword,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 15;
              gl.setConstraints(okbutton,gbc);
              Container contentpane = getContentPane();
              contentpane.setLayout(gl);
              contentpane.add(labelname);
              contentpane.add(labelpassword);
              contentpane.add(textname);
              contentpane.add(textpassword);
              contentpane.add(okbutton);
              okbutton.addActionListener(this);
         public void reset()
              textname.setText("");
              textpassword.setText("");
         public void run()
              try
                   String text = textname.getText();
                   String blank="";
                   if(text.equals(blank))
                      System.out.println("First Enter a UserName");
                   else
                        if(text != blank)
                             date = new Date();
                             gcal = new GregorianCalendar();
                             gcal.setTime(date);
                             out = new FileOutputStream("log.txt",true);
                             p = new PrintStream( out );
                             name = textname.getText();
                             String entry = "UserName:- " + name + " Logged in:- " + gcal.get(Calendar.HOUR) + ":" + gcal.get(Calendar.MINUTE) + " Date:- " + gcal.get(Calendar.DATE) + "/" + gcal.get(Calendar.MONTH) + "/" + gcal.get(Calendar.YEAR);
                             p.println(entry);
                             System.out.println("Record Saved");
                             reset();
                             p.close();
              catch (IOException e)
                   System.err.println("Error writing to file");
         public void actionPerformed(ActionEvent ae)
              String str = ae.getActionCommand();
              if(str.equals("OK"))
                   run();
                   loginframe.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    hai!.
    i am happy to help you.Below is the modified code of ur program.if u still have problem please post.
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    public class MainFrame extends JFrame implements ActionListener
         JDesktopPane desktop;
         JMenuBar menubar;
         JMenu menu,menuemployee;
         public JMenuItem menuitemlogin;
         JMenuItem menuitemquit,itememployee;
         public MainFrame()
              super("MainFrame");
              int inset = 50;
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              setBounds(inset,inset,screenSize.width - inset*2,screenSize.height - inset*2);
              desktop = new JDesktopPane();
              desktop.setBackground(Color.white);
              setContentPane(desktop);
              desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
              setJMenuBar(createMenuBar());
              //createLogin();
         public JMenuBar createMenuBar()
              menubar = new JMenuBar();
              menu = new JMenu("Document");
              menu.setMnemonic(KeyEvent.VK_D);
              menuitemlogin = new JMenuItem("Login");
              menuitemlogin.setMnemonic(KeyEvent.VK_L);
              menuitemlogin.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.ALT_MASK));
              menuitemlogin.setActionCommand("login");
              menuitemlogin.addActionListener(this);
              menuitemquit = new JMenuItem("Quit");
              menuitemquit.setMnemonic(KeyEvent.VK_Q);
              menuitemquit.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_Q, ActionEvent.ALT_MASK));
              menuitemquit.setActionCommand("quit");
              menuitemquit.addActionListener(this);
              menubar.add(menu);
              menu.add(menuitemlogin);
              menu.add(menuitemquit);
              itememployee = new JMenu("Employee");
              itememployee.setMnemonic(KeyEvent.VK_E);
              itememployee.setActionCommand("employee");
    //added this line to disable the itememployee item button     
              itememployee.setEnabled(false);
    //use above the displaying menus all are "JAbstractButton" itememployee.disable();
              menubar.add(itememployee);
              JMenuItem additem = new JMenuItem("Add");
              additem.setMnemonic(KeyEvent.VK_A);
              additem.setActionCommand("add");
              additem.addActionListener(this);
              itememployee.add(additem);
              return menubar;
         public void actionPerformed(ActionEvent ae)
              String str = ae.getActionCommand();
              if(str.equals("login"))
    //added this line to disable login menu:
    menuitemlogin.setEnabled(false);
                   createLogin();
              else if(str.equals("quit"))
                   System.exit(0);
              else if(str.equals("add"))
                   System.out.println("Employee Form Invoked");
                   createEmployee();
         private static void createAndShowGUI()
              JFrame.setDefaultLookAndFeelDecorated(true);
              MainFrame frame = new MainFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(800,600);
              frame.setVisible(true);
         public static void main(String a[])
              createAndShowGUI();
         public void createLogin()
              Login loginobj = new Login();
              loginobj.setVisible(true);
              //itememployee.enable();
              desktop.add(loginobj);
         public void createEmployee()
              Employee employeeobj = new Employee();
              employeeobj.setVisible(true);
              desktop.add(employeeobj);
    class Employee extends JInternalFrame implements ActionListener
         JFrame employeeframe;
         JLabel labelfirstname;
         JLabel labellastname;
         JLabel labelage;
         JLabel labeladdress;
         JLabel labelcity;
         JLabel labelstate;
         JTextField textfirstname;
         JTextField textlastname;
         JTextField textage;
         JTextField textaddress;
         JTextField textcity;
         JTextField textstate;
         JButton buttonsave;
         FileOutputStream out;
         PrintStream p;
         String strfirstname,strlastname,strage,straddress,strcity,strstate;
         GridBagLayout gl;
         GridBagConstraints gbc;
         public Employee()
              super("Employee Details",true,true,true,true);
              setSize(400,300);
              labelfirstname = new JLabel("First Name");
              labellastname = new JLabel("Last Name");
              labelage = new JLabel("Age");
              labeladdress = new JLabel("Address");
              labelcity = new JLabel("City");
              labelstate = new JLabel("State");
              textfirstname = new JTextField(10);
              textlastname = new JTextField(10);
              textage = new JTextField(5);
              textaddress = new JTextField(15);
              textcity = new JTextField(10);
              textstate = new JTextField(10);
              buttonsave = new JButton("Save");
              gl = new GridBagLayout();
              gbc = new GridBagConstraints();
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 3;
              gl.setConstraints(labelfirstname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 3;
              gl.setConstraints(textfirstname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 5;
              gl.setConstraints(labellastname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 5;
              gl.setConstraints(textlastname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 7;
              gl.setConstraints(labelage,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 7;
              gl.setConstraints(textage,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 9;
              gl.setConstraints(labeladdress,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 9;
              gl.setConstraints(textaddress,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 11;
              gl.setConstraints(labelcity,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 11;
              gl.setConstraints(textcity,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 13;
              gl.setConstraints(labelstate,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 13;
              gl.setConstraints(textstate,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 3;
              gbc.gridy = 17;
              gl.setConstraints(buttonsave,gbc);
              Container contentpane = getContentPane();
              contentpane.setLayout(gl);
              contentpane.add(labelfirstname);
              contentpane.add(textfirstname);
              contentpane.add(labellastname);
              contentpane.add(textlastname);
              contentpane.add(labelage);
              contentpane.add(textage);
              contentpane.add(labeladdress);
              contentpane.add(textaddress);
              contentpane.add(labelcity);
              contentpane.add(textcity);
              contentpane.add(labelstate);
              contentpane.add(textstate);
              contentpane.add(buttonsave);
              buttonsave.addActionListener(this);
         public void reset()
              textfirstname.setText("");
              textlastname.setText("");
              textage.setText("");
              textaddress.setText("");
              textcity.setText("");
              textstate.setText("");
         public void actionPerformed(ActionEvent ae)
              String str = ae.getActionCommand();
              System.out.println(str);
              if(str.equalsIgnoreCase("Save"))
         try
         out = new FileOutputStream("myfile.txt",true);
         p = new PrintStream( out );
         strfirstname = textfirstname.getText();
         strlastname = textlastname.getText();
         strage = textage.getText();
         straddress = textaddress.getText();
         strcity = textcity.getText();
         strstate = textstate.getText();
         p.print(strfirstname+"|");
         p.print(strlastname+"|");
         p.print(strage+"|");
         p.print(straddress+"|");
         p.print(strcity+"|");
         p.println(strstate);
         System.out.println("Record Saved");
         reset();
         p.close();
         catch (Exception e)
         System.err.println ("Error writing to file");
    class Login extends JInternalFrame implements ActionListener,InternalFrameListener
         JFrame loginframe;
         JLabel labelname;
         JLabel labelpassword;
         JTextField textname;
         JPasswordField textpassword;
         JButton okbutton;
         String name = "";
         FileOutputStream out;
         PrintStream p;
         Date date;
         GregorianCalendar gcal;
         GridBagLayout gl;
         GridBagConstraints gbc;
         MainFrame obj = new MainFrame();
         public Login()
              super("Login",true,true,true,true);
              setSize(300,300);
              gl = new GridBagLayout();
              gbc = new GridBagConstraints();
              labelname = new JLabel("User");
              labelpassword = new JLabel("Password");
              textname = new JTextField("",9);
              textpassword = new JPasswordField(5);
              okbutton = new JButton("OK");
              okbutton.setMnemonic(KeyEvent.VK_O);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 5;
              gl.setConstraints(labelname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 2;
              gbc.gridy = 5;
              gl.setConstraints(textname,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 10;
              gl.setConstraints(labelpassword,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 2;
              gbc.gridy = 10;
              gl.setConstraints(textpassword,gbc);
              gbc.anchor = GridBagConstraints.NORTHWEST;
              gbc.gridx = 1;
              gbc.gridy = 15;
              gl.setConstraints(okbutton,gbc);
              Container contentpane = getContentPane();
              contentpane.setLayout(gl);
              contentpane.add(labelname);
              contentpane.add(labelpassword);
              contentpane.add(textname);
              contentpane.add(textpassword);
              contentpane.add(okbutton);
              okbutton.addActionListener(this);
              this.addInternalFrameListener(this);
         public void reset()
              textname.setText("");
              textpassword.setText("");
         public void run()
              try
                   String text = textname.getText();
                   String blank="";
                   if(text.equals(blank))
              System.out.println("First Enter a UserName");
              JOptionPane.showMessageDialog(loginframe,"Enter UserName","Alert",JOptionPane.WARNING_MESSAGE);
                   else
                        if(text != blank)
                             date = new Date();
                             gcal = new GregorianCalendar();
                             gcal.setTime(date);
                             out = new FileOutputStream("log.txt",true);
                             p = new PrintStream( out );
                             name = textname.getText();
                             String entry = "UserName:- " + name + " Logged in:- " + gcal.get(Calendar.HOUR) + ":" + gcal.get(Calendar.MINUTE) + " Date:- " + gcal.get(Calendar.DATE) + "/" + gcal.get(Calendar.MONTH) + "/" + gcal.get(Calendar.YEAR);
                             p.println(entry);
                             System.out.println("Record Saved");
                             reset();
                             p.close();
                             System.out.println("Enabling itememployee");
                             obj.itememployee.enable();
    //hai boy add this line to enable itememployee menu:
    itememployee.setEnabled(true);
    // i added this line to close/dispose the internal login frame after ok button is pressed
    this.dispose();
              catch (IOException e)
                   System.err.println("Error writing to file");
         public void actionPerformed(ActionEvent ae)
              String str = ae.getActionCommand();
              if(str.equalsIgnoreCase("OK"))
                   try
                        run();
                        loginframe.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                   catch(Exception e)
    public void internalFrameClosing(InternalFrameEvent e){
    //added this line to again enable login menu if the user closed the login window
                   menuitemlogin.setEnabled(true);
    public void internalFrameOpened(InternalFrameEvent e) {  }
    public void internalFrameIconified(InternalFrameEvent e) {    }
    public void internalFrameDeiconified(InternalFrameEvent e) {   }
    public void internalFrameActivated(InternalFrameEvent e) {    }
    public void internalFrameDeactivated(InternalFrameEvent e) {    }
    public void internalFrameClosed(InternalFrameEvent e) {   }
    }

  • 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);
    }

  • URGENT:problem with memory using swing component

    We use Java SDK 1.4.0-b92 on a Sun Blade Machine with Solaris 8 Operating System.
    We developed a software with a GUI (JFame, JInternalFrame) which have to be refreshed in precise moments and any time we do it there is a big loss of memory(not the Java Virtual Machine Memory but the system memory, see it with the command "vmstat"). It seems that memory isn't released even if we close one or more of the JInternalFrame/JFrame.
    This is a part of our example code which refresh some JTextArea every ten seconds,with the content of a text File called "text.txt" :
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import java.util.*;
    public class MainFrame extends JFrame {
    static JDesktopPane desktop = new JDesktopPane();
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu();
    JMenuItem aggiungi = new JMenuItem();
    int openFrameCount = 0;
    public MainFrame (){
    try{
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    desktop.setBorder(BorderFactory.createLoweredBevelBorder());
    this.setContentPane(desktop);
    Dimension screenSize= Toolkit.getDefaultToolkit().getScreenSize();
    this.setBounds(0, 0, screenSize.width, screenSize.height);
    this.setTitle("Main Frame Prova");
    this.setLocation(0,0);
    this.setVisible(true);
    menu.setText("apri frame");
    aggiungi.setText("Apri");
    aggiungi.addActionListener(new ActionListener () {
    public void actionPerformed(ActionEvent e){
    createFrame();
    menu.add(aggiungi);
    menuBar.add(menu);
    this.setJMenuBar(menuBar);
    catch (Exception e) {e.printStackTrace();}
    private void createFrame (){
    try{
    NsJInternalFrame frame = new NsJInternalFrame("Frame Interno", true, true, true, true);
    openFrameCount++;
    System.out.println("Frame aperti: "+openFrameCount);
    frame.setVisible(true);
    desktop.add(frame);
    frame.setSelected(true);
    frame.setPreferredSize(new Dimension(400,500));
    frame.setSize(new Dimension(400,500));
    finalize();
    catch (Exception e) {e.printStackTrace();}
    catch (Throwable t) {t.printStackTrace();}
    protected void processWindowEvent (WindowEvent e){
    try{
    super.processWindowEvent(e);
    if (e.getID()== WindowEvent.WINDOW_CLOSING) {
    finalize();
    System.exit(0);
    catch (Exception ex) {ex.printStackTrace();}
    catch (Throwable t) {t.printStackTrace();}
    public static void main (String argv[]){
    try {
    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    MainFrame mf = new MainFrame();
    while (true){
    Thread.sleep(10000);
    aggiornaTesto();
    Runtime run = Runtime.getRuntime();
    System.out.println("***********************************************************");
    System.out.println("* Memoria Totale "+run.totalMemory()/1000+" *");
    System.out.println("* Memoria Massima occupabile "+run.maxMemory()/1000+" *");
    System.out.println("* *");
    System.out.println("* --------------------------------------------------------- *");
    System.out.println("* *");
    System.out.println("* Memoria Libera "+run.freeMemory()/1000+" *");
    System.out.println("* *");
    System.out.println("***********************************************************");
    System.runFinalization();
    System.gc();
    catch (Exception e) {e.printStackTrace();}
    private static void aggiornaTesto(){
    JInternalFrame[] frameAperti = desktop.getAllFrames();
    for (int i=0; i<frameAperti.length; i++)
    ((NsJInternalFrame)frameAperti).inizializeText();
    System.out.println("----- "+new Date()+" / Aggiornato testo------");
    System.runFinalization();
    System.gc();
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import java.io.*;
    public class NsJInternalFrame extends JInternalFrame {
    JTextArea textArea=new JTextArea();
    public NsJInternalFrame (String title, boolean resizable, boolean closeable, boolean maximizable, boolean iconifiable){
    super (title, resizable, closeable, maximizable, iconifiable);
    disableEvents (AWTEvent.WINDOW_EVENT_MASK);
    JScrollPane scroll;
    scroll=new JScrollPane(textArea);
    this.setContentPane(scroll);
    this.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
    inizializeText();
    public void inizializeText(){
    try{
    RandomAccessFile raf = new RandomAccessFile("text.txt", "r");
    String text = new String(), line = new String();
    while (true) {
    line = raf.readLine();
    if (line==null) break;
    text= text+line;
    textArea.setText(text);
    finalize();
    raf.close();
    catch (Exception e) {e.printStackTrace();}
    catch (Throwable t) {t.printStackTrace();}
    public void dispose (){
    try{
    finalize();
    super.dispose();
    catch (Exception e) {e.printStackTrace();}
    catch (Throwable t) {t.printStackTrace();}
    text.txt
    HELLO HELLO HELLO
    Help Us Please!!
    [email protected]
    [email protected]

    Yes I'm still following the thread.
    Like i said i only have ovi maps running with PhoNetInfo and even today i tested it again. I managed by changing some settings to get 50MB of free RAM when the phone is idle.
    I changed the amount of allowed RAM to be used by ovi maps to the minimum (10%). This time i had 40MB of free ram before calculating the root (again more or less 600km) without tolls and the fastest root. i continued with PhoNetInfo on and following the value of free RAM and they kept falling till i get again the low memory error.
    I tried then a "solution" that i got from nokia that stated to change the configuration of the internet to online, and it worked perfectly. But i don't think this is a solution since i can't have my phone always connected to the internet. I don't know is where i can suggest that nokia try to solve this problem but already sent an email to the client support stating this.
    I don't think i can install a later version of ovimaps since it comes pre-installed on the phone and i don't see where i can uninstall it and where to find the earlier versions.
    But thanks for the reply,

  • Focus Problem with JTree and Menus

    Hi all,
    I have a problem with focus when editing a JTree and selecting a menu. The problem occurs when the user single clicks on a node, invoking the countdown to edit. If the user quickly clicks on a menu item, the focus will go to the menu item, but then when the countdown finishes, the node now has keyboard focus.
    Below is code to reproduce the problem. Click on the node, hover for a little bit, then quickly click on the menu item.
    How would I go about fixing the problem? Thanks!
    import java.awt.Container;
    import java.awt.GridLayout;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    public class MyTree extends JTree {
         public MyTree(DefaultTreeModel treemodel) {
              setModel(treemodel);
              setRootVisible(true);
         public static void main(String[] args) {
              JFrame frame = new JFrame();
              JMenuBar bar = new JMenuBar();
              JMenu menu = new JMenu("Test");
              JMenuItem item = new JMenuItem("Item");
              menu.add(item);
              bar.add(menu);
              frame.setJMenuBar(bar);
              Container contentPane = frame.getContentPane();
              contentPane.setLayout(new GridLayout(1, 2));
              DefaultMutableTreeNode root1 = new DefaultMutableTreeNode("Root");
              root1.add(new DefaultMutableTreeNode("Root2"));
              DefaultTreeModel model = new DefaultTreeModel(root1);
              MyTree tree1 = new MyTree(model);
              tree1.setEditable(true);
              tree1.setCellEditor(
                   new ComponentTreeCellEditor(
                        tree1,
                        new ComponentTreeCellRenderer()));
              tree1.setRowHeight(0);
              contentPane.add(tree1);
              frame.pack();
              frame.show();
    import java.awt.FlowLayout;
    import java.util.EventObject;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultTreeCellEditor;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreeCellEditor;
    import javax.swing.tree.TreeCellRenderer;
    public class ComponentTreeCellEditor
         extends DefaultTreeCellEditor
         implements TreeCellEditor {
         private String m_oldValue;
         private TreeCellRenderer m_renderer = null;
         private DefaultTreeModel m_model = null;
         private JPanel m_display = null;
         private JTextField m_field = null;
         private JTree m_tree = null;
         public ComponentTreeCellEditor(
              JTree tree,
              DefaultTreeCellRenderer renderer) {
              super(tree, renderer);
              m_renderer = renderer;
              m_model = (DefaultTreeModel) tree.getModel();
              m_tree = tree;
              m_display = new JPanel(new FlowLayout(FlowLayout.LEFT));
              m_field = new JTextField();
              m_display.add(new JLabel("My Label "));
              m_display.add(m_field);
         public java.awt.Component getTreeCellEditorComponent(
              JTree tree,
              Object value,
              boolean isSelected,
              boolean expanded,
              boolean leaf,
              int row) {
              m_field.setText(value.toString());
              return m_display;
         public Object getCellEditorValue() {
              return m_field.getText();
          * The edited cell should always be selected.
          * @param anEvent the event that fired this function.
          * @return true, always.
         public boolean shouldSelectCell(EventObject anEvent) {
              return true;
          * Only edit immediately if the event is null.
          * @param event the event being studied
          * @return true if event is null, false otherwise.
         protected boolean canEditImmediately(EventObject event) {
              return (event == null);
    }

    You can provide a cell renderer to the JTree to paint the checkBox.
    The following code checks or unchecks the box with each click also:
    _tree.setCellRenderer(new DefaultTreeCellRenderer()
      private JCheckBox checkBox = null;
      public Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean selected,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus)
        // Each node will be drawn as a check box
        if (checkBox == null)
          checkBox  = new JCheckBox();
          checkBox .setBackground(tree.getBackground());
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
        checkBox.setText(node.getUserObject().toString());
        checkBox.setSelected(selected);
        return checkBox;
    });

  • Problem with Jtree and a checkbox

    Hello,
    I have a problem with my tree implementation.
    I create a tree and i want to add a checkbox in each node.
    this is my code :
    DefaultMutableTreeNode root;
    root = new DefaultMutableTreeNode(new JCheckBox());
    DefaultTreeModel model = new DefaultTreeModel(root);
    _tree = new JTree(model);
    eastpane.add(tree);
    THe problem is that my checkbox doesn't appear. And a message appears
    instead of my checkbox.
    But my tree appears.
    Can anyone help me .
    Thanks

    You can provide a cell renderer to the JTree to paint the checkBox.
    The following code checks or unchecks the box with each click also:
    _tree.setCellRenderer(new DefaultTreeCellRenderer()
      private JCheckBox checkBox = null;
      public Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean selected,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus)
        // Each node will be drawn as a check box
        if (checkBox == null)
          checkBox  = new JCheckBox();
          checkBox .setBackground(tree.getBackground());
        DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
        checkBox.setText(node.getUserObject().toString());
        checkBox.setSelected(selected);
        return checkBox;
    });

  • Problem with java swing button and loop

    Problem with java swing button and loop
    I�m using VAJ 4.0. and I�m doing normal GUI application. I have next problem.
    I have in the same class two jswing buttons named start (ivjGStart) and stop (ivjGStop) and private static int field named Status where initial value is 0. This buttons should work something like this:
    When I click on start button it must do next:
    Start button must set disenabled and Stop button must set enabled and selected. Field status is set to 1, because this is a condition in next procedure in some loop. And then procedure named IzvajajNeprekinjeno() is invoked.
    And when I click on stop button it must do next:
    Start button must set enabled and selected and Stop button must set disenabled.
    Field status is set to 0.
    This works everything fine without loop �do .. while� inside the procedure IzvajajNeprekinjeno(). But when used this loop the start button all the time stay (like) pressed. And this means that a can�t stop my loop.
    There is java code, so you can get better picture:
    /** start button */
    public void gStart_ActionEvents() {
    try {
    ivjGStart.setEnabled(false);
    ivjGStop.setEnabled(true);
    ivjGStop.setSelected(true);
    getJTextPane1().setText("Program is running ...");
    Status = 1;
    } catch (Exception e) {}
    /** stop button */
    public void gStop_ActionEvents() {
    try {
    ivjGStart.setEnabled(true);
    ivjGStart.setSelected(true);
    ivjGStop.setEnabled(false);
    getJTextPane1().setText("Program is NOT running ...");
    Status = 0;
    } catch (Exception e) {
    /** procedure IzvajajNeprekinjeno() */
    public void IzvajajNeprekinjeno() {  //RunLoop
    try {
    int zamik = 2000; //delay
    do {
    Thread.sleep(zamik);
    PreberiDat(); //procedure
    } while (Status == 1);
    } catch (Exception e) {
    So, I'm asking what I have to do, that start button will not all the time stay pressed? Or some other aspect of solving this problem.
    Any help will be appreciated.
    Best regards,
    Tomi

    This is a multi thread problem. When you start the gui, it is running in one thread. Lets call that GUI_Thread so we know what we are talking about.
    Since java is task-based this will happen if you do like this:
    1. Button "Start" is pressed. Thread running: GUI_Thread
    2. Event gStart_ActionEvents() called. Thread running: GUI_Thread
    3. Method IzvajajNeprekinjeno() called. Thread running: GUI_Thread
    4. Sleep in method IzvajajNeprekinjeno() on thread GUI_Thread
    5. Call PreberiDat(). Thread running: GUI_Thread
    6. Check status. If == 1, go tho 4. Thread running: GUI_Thread.
    Since the method IzvajajNeprekinjeno() (what does that mean?) and the GUI is running in the same thread and the event that the Start button has thrown isn't done yet, the program will go on in the IzvajajNeprekinjeno() method forever and never let you press the Stop-button.
    What you have to do is do put either the GUI in a thread of its own or start a new thread that will do the task of the IzvajajNeprekinjeno() method.
    http://java.sun.com/docs/books/tutorial/uiswing/index.html
    This tutorial explains how to build a multi threaded gui.
    /Lime

  • Problem with CheckBox as table cell renderer

    i m making a JTable having three columns.
    i m also making a cellRenderer of my own MyRenderer
    extending Jcheckbox and implementing TableCellRenderer
    now i m setting MyRenderer as renderer for third column in my table and
    DefaultCellEditor with jcheckbox as parameter as cell editor for this column
    the code is like this--------------------
    ****making of JTable****
    table= new JTable(3,3);
    JScrollPane scrollPane = new JScrollPane(table);
    TableColumn tableColumn = table.getColumn("Male"); // let us suppose that this gives third column
    tableColumn.setCellRenderer(new MyRenderer ());
    tableColumn.setCellEditor(new DefaultCellEditor(new JCheckBox()));
    *****The classs implementing TableCellRenderer is given below******
    class MyRenderer extends JCheckBox implements TableCellRenderer{
    public MyRenderer(){
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column){
    if(value != null){
    Boolean booleanValue = (Boolean)value;
    setSelected(booleanValue.booleanValue());
    return this;
    ***********************************Problem****************************
    The problem is that when we click on the cell of that column first time,
    all the cells are selected.
    I don't want to use getColumnClass() method for this problem .
    If possible , please give some other solution.
    what is the problem behind this,If anybody can help us.
    Thanks in advance.

    I think the problem is, when the value is null the checkbox return with the selected state, b'coz u r
    returning the checkbox (as it is). so pl'z try with below code (ADDED).
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column){
    if(value != null){
    Boolean booleanValue = (Boolean)value;
    setSelected(booleanValue.booleanValue());
    else /// ADDED
    setSelected(false);/// ADDED
    return this;
    Nediaph.

  • Problem with Checkbox that disables/enables other components.

    Hi
    As I show in the title, I have problems with a checkbox that enables/disables another components (three exactly).
    I have done the follow:
    1.- Set property "AutoSubmit" true in the SelectOneChoice
    2.- Set "Disabled" property true or false depending if the SelectOneChoice is selected or not
    (#...selectBooleanCheckbox.value?false:true})
    3.- Set the Partial triggers to the SelectOneChoice in the three components.
    CASE 1: The SelectOneChoice is unmarked. The three components appears disabled and when I mark the SelectOneChoice, this components appears enabled. The thing works ;)
    CASE 2: The SelectOneChoice is marked. The three components appears enabled and when I unmark the SelectOneChoice, the components continue enabled. They don't disable until I press the submit button.
    how can i make that the components appears disabled when i unmark the checkbox?
    i try with de ChangeValueListener, but it only works where the SelectOneChoice changes from unmarked to marked.
    thanks!

    I think the problem is, when the value is null the checkbox return with the selected state, b'coz u r
    returning the checkbox (as it is). so pl'z try with below code (ADDED).
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus,
    int row, int column){
    if(value != null){
    Boolean booleanValue = (Boolean)value;
    setSelected(booleanValue.booleanValue());
    else /// ADDED
    setSelected(false);/// ADDED
    return this;
    Nediaph.

Maybe you are looking for

  • Error while deleting the Temp File

    Please see the following results I have the temp_03.dbf in dba_temp Files but have no id in v$temp_space_header. So when I am trying to do the alter tablespace drop file its giving me error. Cant drop the file at this time. Any recommendations will h

  • ITunes can't see my iPOD Music

    iTUnes can'r see mhy Fifth Gen iPOD Music Posted: Mar 25, 2007 1:12 AM Click to reply to this topic Reply email Email I keep my laptop music on an external drive. Today the drive accidentally got disconnected and thus iTunes (latest version Win XP) d

  • Unable to print in excel format

    Hi, I develop report in xml publisher and my apps version is 11.5.10.2 But my report is not printing in excel format. Any idea on this.... Regards Zaheer

  • The Wackiest thing, Numbers match, but it's half the size

    Ok, This is the code (document class). public function LoadingDoors()                //Check for a Reference to the stage.                if (stage){                     //already have stage access                     onAddedToStage();               

  • Error in Role creation in ERM

    Hi Experts, We are working in demo systems with GRC AC 5.3_10.1. We are trying to create a single role in ERM. When trying to add Function ID PR01 or PR91, it is throwing error as "unknown error occurred while performing operation (Cannot assign a ja