Help in jwindow

hi there
i want to build an application with jwindow but i have a problem , the jwindow doesn't have a taskbar button how can i create one

I am not sure if there is no way (I am not an expert) but I would think that it might be easier to change JFrame to behave the way you need (like a JWindow). But since I don't know what you are trying to do or if it is possible to get the taskbar or how hard it would be, I am just guessing / suggesting. :-)

Similar Messages

  • JFrames Parent-Child Relationship

    Hi Experts,
    I m facing a problem. I have one JFrame in which one JButton is added. On click of this JButton one other JFrame open up or we can say pop up.
    Now I want that user can not click on parent JFrame ( which open new JFrame ) until he close this new JFrame.
    Like, for example, while viewing html page when we get Alert, we have to click on it to go back to page, without clicking on it we are not allowed to go back to page.
    Same functionality I want in Swing.
    Anyone can help me ? ? ?
    Dhwanit Shah
    [email protected]

    Thanx for your reply.
    But problem is I want to add so many components in my new opening window like textfield,buttons,check box ..etc.
    And as i know this is not possible with JDialog , so is there any option remaining ?
    I am trying to do it with the help of JWindow by using it's method getOwner() and constructor JWindow(Frame owner) or JWindow(JWindow owner) ..i am trying ...i m not sure.
    Could anyone focus on this issue ???
    Dhwanit Shah
    [email protected]

  • Urgent Help jdk 1.4.2  JWindow and Text Field

    Go thgh this code pls
    import java.awt.*;
    import javax.swing.*;
    class Test1 extends JWindow
         TextField tf;
         public Test1()
              Container contentPane = getContentPane();
              contentPane.setLayout(new FlowLayout());
              tf = new TextField(10);
              contentPane.add(tf);
    public class Test extends Test1
         public static void main(String[] args)
              Test1 t = new Test1();
              t.setSize(300,200);
              t.show();
    when the above application is compiled and run using jdk1.4 0r above the text field gets disabled. ie nothing gets entered in the text field.
    However if i extend JFrame instead of JWindow then everything is fine.
    Also note that the same code compiles and runs perfectly on 1.3.1 ie even if i extend JWindow i am able to enter text in text field.
    Pls help asap

    this works because theres an owner frame behind the window:import java.awt.*;
    import javax.swing.*;
    class Test extends JWindow
         static TextField tf;
         public Test(JFrame owner)
              super(owner);
              Container contentPane = getContentPane();
              contentPane.setLayout(new FlowLayout());
              tf = new TextField(10);
              contentPane.add(tf);
         public static void main(String[] args)
              JFrame frame = new FrameForWindow();
              Test t = new Test(frame);
              t.setSize(300, 200);
              frame.setVisible(true);
              t.setVisible(true);
    class FrameForWindow extends JFrame{}regards,
    Tim

  • JWindow class please help me

    sir<br>
    i design a splash window by the use of JWindow class
    i use the following constructor
    public class splash extends JWindow
    //get content pane and set by the setContentPane method
    and add the three panels in it.
    One JPanel have a JTextField
    but JTextField is not accept the input or focus
    means i try to write text in it but it not work
    the code as follows
    //Create Jwindow
    import javax.swing.*;
    import java.awt.*;
    public class SplashScreen extends JWindow
    public static void main(String args[])
    new SplashScreen().setVisible(true);
    //define Variables
    Toolkit tk=Toolkit.getDefaultToolkit();
    Container cp=getContentPane();
    SplashScreenPanel1 p1;
    SplashScreenPanel2 p2;
    SplashScreenPanel3 p3;
    SplashScreen()
    Dimension d=tk.getScreenSize();
    p1=new SplashScreenPanel1(d.getWidth(),d.getHeight());
    p2=new SplashScreenPanel2(d.getWidth(),d.getHeight());
    p3=new SplashScreenPanel3(d.getWidth(),d.getHeight());
    this.setSize(d);
    this.setContentPane(cp);
    this.getContentPane().setLayout(null);
    cp.setBackground(new Color(47,168,122));
    p1.setBounds(new Rectangle(0,(int)(d.getHeight()-100),(int)d.getWidth(),100));
    p2.setBounds(new Rectangle(0,0,(int)d.getWidth(),100));
    p3.setBounds(new Rectangle(0,100,(int)(d.getWidth()),400));
    this.getContentPane().add(p1);
    this.getContentPane().add(p2);
    this.getContentPane().add(p3);
    p1.b1.requestFocus();
    }//end of spalshscreen
    create JPanel
    public class spashscreenpanel3 extends JPanel
    JTextField t=new JTextField();
    splashscreenpanel3
    this.setSize(200,100);
    this.setLayout(null);
    t.setBounds(10,20,100,20);
    this.add(t);
    }//end of JPanel
    Please help me i am very thankful to u

    Some helpful information is here:
    http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
    import javax.swing.*;
    import java.awt.*;
    public class hamad extends JFrame
      public static void main(String args[]) 
        new hamad();
      //define Variables
      SplashScreenPanel1 p1;
      SplashScreenPanel2 p2;
      SplashScreenPanel3 p3;
      JWindow window;
      public hamad()
        createWindow(this);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300,200);
        setLocation(500,300);
        setVisible(true);
      private void createWindow(JFrame frameReference) {
        window = new JWindow(frameReference);
        Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension d=tk.getScreenSize();
        p1=new SplashScreenPanel1();
        p2=new SplashScreenPanel2();
        p3=new SplashScreenPanel3();
        window.getContentPane().add(p1, "North");
        window.getContentPane().add(p2, "Center");
        window.getContentPane().add(p3, "South");
        window.setSize(d.width/4, d.width/4);
        window.setLocation(100,100);
        window.setVisible(true);
      private class SplashScreenPanel1 extends JPanel
        JTextField field;
        public SplashScreenPanel1()
          setBackground(new Color(200,150,190));
          setPreferredSize(new Dimension(100,50));
          field = new JTextField();
          field.setPreferredSize(new Dimension(100, 20));
          add(field);
      private class SplashScreenPanel2 extends JPanel
        JTextField field;
        public SplashScreenPanel2()
          setBackground(new Color(220,90,180));
          field = new JTextField();
          field.setPreferredSize(new Dimension(75,20));
          add(field);
      //create JPanel
      private class SplashScreenPanel3 extends JPanel
        JTextField t=new JTextField();
        public SplashScreenPanel3()
          setBackground(Color.pink);
          setPreferredSize(new Dimension(100,50));
          setLayout(null);
          t.setBounds(10,20,100,20);
          add(t);
      }//end of JPanel
    }//end of spalshscreen

  • JWindow JTextArea Issue... Help

    Hello guys and gals,
    I'm sure this issue I'm having is very common here to us programmers and people have asked this question several times.
    I'm using JWindow right now and I have a JTextArea that's not editable at all even though I've set it to be editable.. All I can do is setText to be there... It must be a bug or something..
    I will not convert to JFrame though it's easier to do so. JWindow is needed. Is it possible to my JTextArea editable so I can continue to program or am I just wasting time? Can anyone explain to me in simple terms to fix this issue? Maybe my code is incorrect.. Here's my entire code:
    import javax.swing.*;
    import javax.swing.border.EtchedBorder;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class JustToSee extends JWindow implements ActionListener
         Dimension screenSize =
            Toolkit.getDefaultToolkit().getScreenSize();              
         private JPanel background, outpassBox, inpassBox, wrongBox,
         passBoxoutSide, wrongBoxoutside, inwrongBox;
         private JButton exit;
         private JLabel wrongL, passL;
                         private JTextArea wrongT;
         public JustToSee()
              setBackground(Color.BLACK);
              Container pane = getContentPane();
              pane.setLayout(null);
              background = new JPanel();
              background.setSize(Toolkit.getDefaultToolkit().getScreenSize());
              background.setBackground(Color.black);
              background.setLayout(null);          
              outpassBox = new JPanel();
              outpassBox.setSize(650, 750);
              outpassBox.setLocation(600,30);
              outpassBox.setBackground(Color.black);
              outpassBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.black, Color.blue));
              outpassBox.setLayout(null);
              inpassBox = new JPanel();
              inpassBox.setSize(610,600);
              inpassBox.setLocation(20, 120);
              inpassBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.black, Color.blue));
              inpassBox.setBackground(Color.black);
              inpassBox.setLayout(null);
              wrongBox = new JPanel();
              wrongBox.setSize(300, 750);
              wrongBox.setLocation(50, 30);
              wrongBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.black, Color.blue));
              wrongBox.setBackground(Color.black);
              wrongBox.setLayout(null);
              passBoxoutSide = new JPanel();
              passBoxoutSide.setSize(610, 80);
              passBoxoutSide.setLocation(20,30);
              passBoxoutSide.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED,Color.black, Color.blue));
              passBoxoutSide.setBackground(Color.black);
              passBoxoutSide.setLayout(null);
              wrongBoxoutside = new JPanel();
              wrongBoxoutside.setSize(260, 80);
              wrongBoxoutside.setLocation(20, 30);
              wrongBoxoutside.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED,Color.black, Color.blue));     
              wrongBoxoutside.setBackground(Color.black);     
              wrongBoxoutside.setLayout(null);
              inwrongBox = new JPanel();
              inwrongBox.setSize(260, 600);
              inwrongBox.setLocation(20, 120);
              inwrongBox.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED,Color.black, Color.blue));
              inwrongBox.setBackground(Color.red);
              inwrongBox.setLayout(null);
              passL = new JLabel("Password Field...");
              passL.setForeground(Color.blue);
              passL.setFont(new Font("Computerfont", Font.BOLD, 24));
              passL.setSize(300, 60);
              passL.setLocation(10, 30);
              wrongL = new JLabel("Wrong Passwords...");
              wrongL.setForeground(Color.blue);
              wrongL.setFont(new Font("Computerfont", Font.BOLD, 24));
              wrongL.setSize(300, 60);
              wrongL.setLocation(10, 30);
              wrongT = new JTextArea(50, 1);//Inside the 2nd JPanel on the left side. It fills up the entire panel
              wrongT.setBackground(Color.white);
              wrongT.setForeground(Color.blue);
              wrongT.setFont(new Font("Computerfont", Font.BOLD, 18));
              wrongT.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED,Color.black, Color.blue));
              wrongT.setLocation(0,0);
              wrongT.setSize(260, 600);
              wrongT.setText("This is where the text goes! \nThis needs to be edited. Help =(");
              wrongT.setLineWrap(true);
              wrongT.setEditable(true);
              wrongT.setFocusable(true);
              exit = new JButton("EXIT");
              exit.setBackground(Color.black);
              exit.setForeground(Color.blue);
              exit.setFont(new Font("Computerfont",Font.BOLD,16));
              exit.setLocation(380, 100);
              exit.setSize(100, 60);
              exit.addActionListener(this);
              pane.add(background);
              background.add(exit);
              background.add(outpassBox);
              background.add(wrongBox);
              outpassBox.add(inpassBox);
              outpassBox.add(passBoxoutSide);
              passBoxoutSide.add(passL);
              wrongBox.add(wrongBoxoutside);
              wrongBox.add(wrongT);          
              wrongBoxoutside.add(wrongL);
              wrongBox.add(inwrongBox);
              inwrongBox.add(wrongT);          
         public void actionPerformed(ActionEvent e)
              if(e.getSource() == exit)
                   System.exit(0);
         public static void main(String[] args)
         JustToSee w = new JustToSee();
         GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(w);
    }Your help is greatly appreciated... =) Take care.
    Gabriel Young

      public JustToSee()
        super(new JFrame(){public boolean isShowing(){return true;}});//<----------
        setBackground(Color.BLACK);

  • JWindow closing with ALT F4 leaving child components  help please.....

    Hi all
    I come acrossed one problem i.e i have my main application as JWindow and a button and when i click it iam getting an JOptionPane/JRame/JDialog and set modal if its dialog and set modal through window activate and deactivate if its JFrame the problem is when i click on JWindow and press ALT F4 my JWindow is closing leaving the child Component (i.e JDialog/JOptionPane... etc)now i want to not to close JWindow if there was any dialog,optionpane opened any ideas/views/sugesstions please suggest...
    Kalpana

    Hi!
    How did you created your frames / dialogs?
    You must give the reference of the JWindow instance as owner for your child frames...
    I hope this helps you,
    Taoufik

  • Help: How to use JWindow as Popup

    Hi there,
    I am developing a program & I wanted to design it with a screen like the Mac OS (tiger?) desktop. That is menu (button bar) at the bottom of the screen (the program's screen - Not the OS).
    I thought I should use a JWindow to do it.
    HOW I WOULD LIKE THE POPUP TO BEHAVE:
    - Only appears when a user moves the mouse towards the bottom of the screen.
    - To disappear (hide) when the user clicks somewhere else on the screen [when focus is lost(?)]
    - To change its position relative to the program. That is, if the program is resized etc...
    I NEED YOUR HELP ON
    The design issues I should take into consideration. I mean interfaces I should implement etc...
    Thanks in advance.
    Yours,
    Me

    Okay, sorry for the late reply, I dont go on the net much.
    With the focus issues, it could be very tricky to know when exactly the Window has lost focus cause a component within the window could still have the focus, hence the window would be in focus.
    One way, could be to add a common FocusListener to all the components within the window by using a recursion method, and allow this FocusListener to determine when all the elements within the window have lost focus, so as to call the window hiding function
    public void addFocusListener(Component c, FocusListener fl) {
      c.addFocusListener(fl);
      if(c instanceof Container) {
         Container cn = (Container)c;
         for(int i = 0; i < cn.getComponents().length; i++) {
             addFocusListener(cn.getComponent(i), fl);
    // also the focus listener could be like this
    class FocusChecker implements FocusListener {
       public void focusLost(FocusEvent e) {
          Component source = (Component)e.getSource();
          if(popupWindow.isAncestorOf(source)) {
              if(!popupWindow.isFocussed()) { // check if the window has a focussed component
                 moveWindowIntoHiding();  // call the method to hide to window
    }This is just a general guideline. Think around this to hide the window when it looses focus
    ICE

  • How can I make a default border for a JWindow?

    I have a JWindow object that is created when a button is pressed in a JFrame. I want the JWindow to have the same type of border as the JFrame from which it's created. However, the JWindow is not created automatically with a border as the JFrame is, so I don't know how to set the border abstractly so that whatever border is used for the JFrame, per he default L&F, will also be used for the JWindow.
    I tried grabbing the border object from the JFame instance itself, but there is no such field in JFrame or any of its ancestor classes. I looked at UIDefaults, but I have no idea how this class can be used to get what I want. For example, if I use UIDefaults.getBorder(Object obj), what do I specify for the argument?
    I'd be happy with an abstract or a concrete solution. That is, either using the default Border for top level containers in the current L&F, or by grabbing an actual Border instance from a JFrame object.
    -Mark

    Also, I'm curious why you said that JFrame is not a swing component.A Swing component extends JComponent. Basically this means that all the painting of the component is done in Java. You can add Borders to any Swing component. It is called a light weight component. A light weight component cannot exist by itself on the window desktop.
    JFrame, JDialog and JWindow are top level components. They can exist on their own on the windows desktop because essentially they are Windows native components. They have been fancied up to make it easy for you to access and add other Swing components to it which is why they are found in the swing package.
    A Windows border is not the same thing as a Swing Border and there is no way to access the native windows border and use it in a Swing application (that I know of anyway). Swing Borders are not used in a normal JFrame, the Windows border is used. You can however, turn off the use of Windows decorations and use Swing painted decorations. Read the tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html#setDefaultLookAndFeelDecorated]Specifying Windows Decorations. However, this doesn't really help you with your Border problem. If you look at the source code for the FrameBorder, you will find that the "blue" color of the Border is only painted for "active" windows and a JWindow can never be the active window, only the parent JFrame or JDialog is considered active.
    Here is a simple program for you to play around with:
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class FrameDecorated
         public static void main(String[] args)
              JFrame.setDefaultLookAndFeelDecorated(true);
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
              frame.setSize(300, 300);
              frame.setVisible(true);
              Border border = frame.getRootPane().getBorder();
    //          Border border = UIManager.getBorder( "RootPane.frameBorder" );
              System.out.println( border );
              JWindow window = new JWindow(frame);
              JPanel contentPane = (JPanel)window.getContentPane();
              contentPane.add(new JTextField(), BorderLayout.NORTH);
              contentPane.setBorder( border );
              window.setSize(300, 300);
              window.setLocationRelativeTo( null );
              window.setVisible( true );
              System.out.println("Window:" + window);
              Window ancestor = SwingUtilities.getWindowAncestor(contentPane);
              System.out.println("Ancestor:" + ancestor);
              System.out.println(ancestor.isActive());
              System.out.println(frame.isActive());
    }

  • Help needed, Createing Dynamic User input

    Hello,
    I am attempting to create some dynamic user input by "predicting" what the user requires in a text box.
    For example if the user enters "Smi" I have a select list pop up which gives the user all options that begin with "Smi".
    I am able to achieve the popups but the interface is quite jerky and not terribly responsive I am trying to solve this by using a thread which starts and stops when new input is received but it is still not quite right.
    The program uses a Sorted TreeSet to hold the data (I thought this would give me a quick search time) and a simple interface at this stage.
    Any help would be fantastic
    Thanks in advance :P
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.text.*;
    import java.util.*;
       /** This program represents part of a larger user interface for allowing the
       user to select data from a file or database.
       <p>
       When the program starts up, it will read in data from a given file, and hold
       it in some type of container allowing rapid access.
       <p>
       The user may then type in the first few letters of the surname of a person,
       and this program should immediately present in a popup dialog the names which
       match.  The user will be able to click on one of the names in the popup and
       that will cause all data about that person to be displayed in the JTextArea
       at the bottom of the window.
       <p>
       This program requires the FormLayout.class, FormLayout$Placement.class, and
       FormLayout$Constraint.class files in the same directory
       (folder) or in its classpath.  These is provided separately.
    class PartMatch extends JFrame implements Runnable
                        /** Close down the program. */
       JButton quitbtn;
                        /** Field for the surname. */
       JTextField namefld;
                        /** Full details of the person(s). */
       JTextArea  results;
                        /** Popup dialog to display the names and addresses which
                        match the leading characters given in namefld. */
       Chooser matches;
                      /** Default background color for a window. */
       final static  Color            defBackground = new Color(0xD0C0C0);
                      /** Default foreground color for a window. */
       final static  Color            defForeground = new Color(0x000000);
                      /** Default background color for a field */
       final static  Color            fldBackground = new Color(0xFFFFFF);
                      /** Default background color for a button */
       final static  Color            btnBackground = new Color(0xF0E0E0);
       final static  Color            dkBackground = new Color(0xB0A0A0);
                      /** Larger font */
       final static  Font bold = new Font("Helvetica", Font.BOLD, 30);
       TreeSet members;
       String input;
       String[] found;
       public static void main(String arg[])
          UIManager.put("TextField.background",fldBackground);
          UIManager.put("TextField.foreground",defForeground);
          UIManager.put("TextField.selectionBackground",btnBackground);
          UIManager.put("TextArea.background",fldBackground);
          UIManager.put("TextArea.foreground",defForeground);
          UIManager.put("TextArea.selectionBackground",btnBackground);
          UIManager.put("Panel.background",defBackground);
          UIManager.put("Label.background",defBackground);
          UIManager.put("Label.foreground",defForeground);
          UIManager.put("Button.background",btnBackground);
          UIManager.put("Button.foreground",defForeground);
          UIManager.put("CheckBox.background",defBackground);
          UIManager.put("ScrollBar.background",defBackground);
          UIManager.put("ScrollBar.thumb",btnBackground);
          UIManager.put("ComboBox.background",btnBackground);
          UIManager.put("ComboBox.selectionBackground",dkBackground);
          PartMatch trial = new PartMatch(arg);
       public PartMatch( String [] arg )
          super("Part Match");
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          Container cpane = getContentPane();
          FormLayout form = new FormLayout(cpane);
          JLabel lab1 = new JLabel("Fetch details") ;
          lab1.setFont( bold );
          form.setTopAnchor( lab1, 4 );
          form.setLeftAnchor( lab1, 4 );
          JLabel lab2 = new JLabel("Surname: ") ;
          form.setTopRelative( lab2, lab1, 4 );
          form.setLeftAlign( lab2, lab1 );
          namefld = new JTextField( 30 );
          form.setBottomAlign( namefld, lab2 );
          form.setLeftRelative( namefld, lab2, 4 );
          namefld.addCaretListener( new CaretListener()
             public void caretUpdate(CaretEvent e)
                 showMatches();
          quitbtn = new JButton( "Quit" );
          quitbtn.addActionListener( new ActionListener()
             public void actionPerformed(ActionEvent e)
                quitProcessing();
          form.setBottomAlign( quitbtn, namefld );
          form.setLeftRelative( quitbtn, namefld, 15 );
          results = new JTextArea( 10,50 );
          results.setEditable(false);
          JScrollPane jsp = new JScrollPane( results,
                                     JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
          form.setTopRelative( jsp, lab2, 6 );
          form.setLeftAlign( jsp, lab2 );
          form.setBottomAnchor( jsp, 5 );
          form.setRightAnchor( jsp, 5 );
          form.setRightAnchor( quitbtn, 5 );
          matches = new Chooser( this );
          //matches.setUndecorated(true);
          pack();
          setVisible(true);
          namefld.requestFocus();
          if (arg.length > 0) init(arg[0]);
          else init("triathlon.txt"); //<<<<<<<<<<<<<<<< Place the default filename here
          /** Called once only, at the end of the constructor, to read the data
            * from the membership file.
       public void init( String fname )
          members = new TreeSet();
           try {
               FileReader fr = new FileReader(new File (fname));
               Scanner scan = new Scanner(fr);
               trimember cmem;
               String cLine, eTag, memberNo, first, last, gender, yob, tel ,addr,
                       club;
               while(scan.hasNextLine())
                   cLine = scan.nextLine();
                   Scanner scan2 = new Scanner(cLine);
                   scan2.useDelimiter(";");
                   eTag = scan2.next().trim();
                   memberNo = scan2.next().trim();
                   first = scan2.next().trim();
                   last = scan2.next().trim();
                   gender = scan2.next().trim();
                   yob = scan2.next().trim();
                   tel = scan2.next().trim();
                   addr = scan2.next().trim();
                   club = scan2.next().trim();
                   cmem = new trimember(eTag, memberNo, first, last, gender, yob,
                           tel, addr, club);
                   members.add(cmem);
           catch (FileNotFoundException ex)
               results.append("Sorry can't find the input file\n");
               results.append("Please check file name and location and try again");
               ex.printStackTrace();
          /** Called every time there is a change in the contents of the text field
            * namefld.  It will first clear the text area.  It then needs to search
            * through the container of data to find all records where the surname
            * starts with the characters that have been typed.  The names and
            * addresses need to be set up as strings and placed in
            * an array of Strings.  This can be placed in the "matches" window and
            * displayed for the user, inviting one to be selected.
            * <p>
            * The performance of this is very important.  If necessary, it may be
            * necessary to run as a separate thread so that the user interface is
            * not delayed.  It is essential that the user be able to type letters at a
            * reasonable speed and not have the keystroke processing held up by
            * previous text.
       public void showMatches( )
           run();
                // First clear the text area
          //results.setText("");
                // Determine the leading characters of the surname that is wanted
                input = namefld.getText();
                // Locate the data for this name, and display each matching item
                //  in the JTextArea ...
                // Example of how to set the data in the popup dialog
          matches.list.setListData(found);
          matches.pack();   // resize the popup
                // set the location of the popup if it is not currently visible
          if ( ! matches.isVisible())
             Dimension sz = matches.getSize();
             Point mouse = getMousePosition();
             Point framepos = getLocation();
             int x=0, y=0;
             if (mouse == null)
                Point pt = results.getLocation();
                x = pt.x + 20 + framepos.x;
                y = pt.y + 20 + framepos.y;
             else
                x = mouse.x - 2 + framepos.x;
                y = mouse.y - 2 + framepos.y;
             matches.setLocation(x,y);
          matches.setVisible(true);
          namefld.requestFocus();
          /** Perform any final processing before closing down.
       public void quitProcessing( )
          // Any closing work.  Then
          System.exit(0);
        public void run()
            ArrayList<String> foundit = new ArrayList<String>();
            System.out.println(input);
            if(input != null)
            Iterator it = members.iterator();
            while(it.hasNext())
               trimember test = (trimember) it.next();
               if (test.last.startsWith(input))
                   foundit.add(test.last +", "+ test.first);
            found = new String[foundit.size()];
            for(int i=0; i<foundit.size();i++)
                found[i] = foundit.get(i);
         /** A window for displaying names and addresses from the data set which
          match the leading characters in namefld.
          <p>
          This will automatically pop down if the user moves the mouse out of the
          window.
          <p>
          It needs code added to it to respond to the user clicking on an item in
          the displayed list. */
       class Chooser extends JWindow
                /** To display a set of names and addresses that match the leading
                characters of the namefld text field. */
          public JList list = new JList();
          Chooser( JFrame parent )
             super( parent );
             Container cpane = getContentPane();
             cpane.addMouseListener( new MouseAdapter()
                public void mouseExited(MouseEvent e)
                   Chooser.this.setVisible(false);
             cpane.add("Center",list);
             list.addListSelectionListener( new ListSelectionListener()
                public void valueChanged(ListSelectionEvent e)
                   Chooser.this.setVisible(false);
                   System.out.println("ValueChanged");
                   // First clear the text area
                   results.setText("");
                   String in = (String) list.getSelectedValue();
                   System.out.println("Selected Value was : "+in);
                   String[] inlf = in.split(", ");
                   System.out.println("inlf[0]:"+inlf[0]+" inlf[1]:"+inlf[1]);
                   results.append("Surname \tFirst \teTag \tMemberNo \tSex \tYOB " +
                           "\tTel \tAddress \t\t\tClub\n");
                   Iterator it = members.iterator();
                   while(it.hasNext())
                       trimember test = (trimember) it.next();
                       if (test.last.equals(inlf[0])&&test.first.equals(inlf[1]))
                           results.append(test.toString()+"\n");
                   namefld.requestFocus();
          public class trimember implements Comparable
           String eTag;
           public String memberNo;
           public String first;
           public String last;
           String gender;
           String yob;
           String tel;
           String addr;
           String club;
           public trimember(String eT, String me, String fi, String la,
                   String ge, String yo, String te, String ad, String cl)
               eTag = eT;
               memberNo = me;
               first = fi;
               last = la;
               gender = ge;
               yob = yo;
               tel = te;
               addr = ad;
               club = cl;         
           //To String method to output string of details
           public String toString()
               return last + "\t" + first + "\t" + eTag + "\t" +
                       memberNo + "\t" + gender + "\t" + yob + "\t"+ tel + "\t" +
                       addr + "\t" + club;
           //Compare and sort on Last name
           public int compareTo(Object o)
               trimember com = (trimember) o;
               int lastCmp = last.compareTo(com.last);
               int firstCmp = first.compareTo(com.first);
               int memCmp = memberNo.compareTo(com.memberNo);
               if (lastCmp == 0 && firstCmp !=0)return firstCmp;
               else if (lastCmp==0&&firstCmp==0)return memCmp;
               else return lastCmp;
    }

    Please don't cross-post. It is considered very rude to do that here:
    http://forum.java.sun.com/thread.jspa?messageID=9953193

  • Help needed, Providing Dynamic User input

    Hello,
    I am attempting to create some dynamic user input by "predicting" what the user requires in a text box.
    For example if the user enters "Smi" I have a select list pop up which gives the user all options that begin with "Smi".
    I am able to achieve the popups but the interface is quite jerky and not terribly responsive I am trying to solve this by using a thread which starts and stops when new input is received but it is still not quite right.
    The program uses a Sorted TreeSet to hold the data (I thought this would give me a quick search time) and a simple interface at this stage.
    Any help would be fantastic
    Thanks in advance :P
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.text.*;
    import java.util.*;
       /** This program represents part of a larger user interface for allowing the
       user to select data from a file or database.
       <p>
       When the program starts up, it will read in data from a given file, and hold
       it in some type of container allowing rapid access.
       <p>
       The user may then type in the first few letters of the surname of a person,
       and this program should immediately present in a popup dialog the names which
       match.  The user will be able to click on one of the names in the popup and
       that will cause all data about that person to be displayed in the JTextArea
       at the bottom of the window.
       <p>
       This program requires the FormLayout.class, FormLayout$Placement.class, and
       FormLayout$Constraint.class files in the same directory
       (folder) or in its classpath.  These is provided separately.
    class PartMatch extends JFrame implements Runnable
                        /** Close down the program. */
       JButton quitbtn;
                        /** Field for the surname. */
       JTextField namefld;
                        /** Full details of the person(s). */
       JTextArea  results;
                        /** Popup dialog to display the names and addresses which
                        match the leading characters given in namefld. */
       Chooser matches;
                      /** Default background color for a window. */
       final static  Color            defBackground = new Color(0xD0C0C0);
                      /** Default foreground color for a window. */
       final static  Color            defForeground = new Color(0x000000);
                      /** Default background color for a field */
       final static  Color            fldBackground = new Color(0xFFFFFF);
                      /** Default background color for a button */
       final static  Color            btnBackground = new Color(0xF0E0E0);
       final static  Color            dkBackground = new Color(0xB0A0A0);
                      /** Larger font */
       final static  Font bold = new Font("Helvetica", Font.BOLD, 30);
       TreeSet members;
       String input;
       String[] found;
       public static void main(String arg[])
          UIManager.put("TextField.background",fldBackground);
          UIManager.put("TextField.foreground",defForeground);
          UIManager.put("TextField.selectionBackground",btnBackground);
          UIManager.put("TextArea.background",fldBackground);
          UIManager.put("TextArea.foreground",defForeground);
          UIManager.put("TextArea.selectionBackground",btnBackground);
          UIManager.put("Panel.background",defBackground);
          UIManager.put("Label.background",defBackground);
          UIManager.put("Label.foreground",defForeground);
          UIManager.put("Button.background",btnBackground);
          UIManager.put("Button.foreground",defForeground);
          UIManager.put("CheckBox.background",defBackground);
          UIManager.put("ScrollBar.background",defBackground);
          UIManager.put("ScrollBar.thumb",btnBackground);
          UIManager.put("ComboBox.background",btnBackground);
          UIManager.put("ComboBox.selectionBackground",dkBackground);
          PartMatch trial = new PartMatch(arg);
       public PartMatch( String [] arg )
          super("Part Match");
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          Container cpane = getContentPane();
          FormLayout form = new FormLayout(cpane);
          JLabel lab1 = new JLabel("Fetch details") ;
          lab1.setFont( bold );
          form.setTopAnchor( lab1, 4 );
          form.setLeftAnchor( lab1, 4 );
          JLabel lab2 = new JLabel("Surname: ") ;
          form.setTopRelative( lab2, lab1, 4 );
          form.setLeftAlign( lab2, lab1 );
          namefld = new JTextField( 30 );
          form.setBottomAlign( namefld, lab2 );
          form.setLeftRelative( namefld, lab2, 4 );
          namefld.addCaretListener( new CaretListener()
             public void caretUpdate(CaretEvent e)
                 showMatches();
          quitbtn = new JButton( "Quit" );
          quitbtn.addActionListener( new ActionListener()
             public void actionPerformed(ActionEvent e)
                quitProcessing();
          form.setBottomAlign( quitbtn, namefld );
          form.setLeftRelative( quitbtn, namefld, 15 );
          results = new JTextArea( 10,50 );
          results.setEditable(false);
          JScrollPane jsp = new JScrollPane( results,
                                     JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                     JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED );
          form.setTopRelative( jsp, lab2, 6 );
          form.setLeftAlign( jsp, lab2 );
          form.setBottomAnchor( jsp, 5 );
          form.setRightAnchor( jsp, 5 );
          form.setRightAnchor( quitbtn, 5 );
          matches = new Chooser( this );
          //matches.setUndecorated(true);
          pack();
          setVisible(true);
          namefld.requestFocus();
          if (arg.length > 0) init(arg[0]);
          else init("triathlon.txt"); //<<<<<<<<<<<<<<<< Place the default filename here
          /** Called once only, at the end of the constructor, to read the data
            * from the membership file.
       public void init( String fname )
          members = new TreeSet();
           try {
               FileReader fr = new FileReader(new File (fname));
               Scanner scan = new Scanner(fr);
               trimember cmem;
               String cLine, eTag, memberNo, first, last, gender, yob, tel ,addr,
                       club;
               while(scan.hasNextLine())
                   cLine = scan.nextLine();
                   Scanner scan2 = new Scanner(cLine);
                   scan2.useDelimiter(";");
                   eTag = scan2.next().trim();
                   memberNo = scan2.next().trim();
                   first = scan2.next().trim();
                   last = scan2.next().trim();
                   gender = scan2.next().trim();
                   yob = scan2.next().trim();
                   tel = scan2.next().trim();
                   addr = scan2.next().trim();
                   club = scan2.next().trim();
                   cmem = new trimember(eTag, memberNo, first, last, gender, yob,
                           tel, addr, club);
                   members.add(cmem);
           catch (FileNotFoundException ex)
               results.append("Sorry can't find the input file\n");
               results.append("Please check file name and location and try again");
               ex.printStackTrace();
          /** Called every time there is a change in the contents of the text field
            * namefld.  It will first clear the text area.  It then needs to search
            * through the container of data to find all records where the surname
            * starts with the characters that have been typed.  The names and
            * addresses need to be set up as strings and placed in
            * an array of Strings.  This can be placed in the "matches" window and
            * displayed for the user, inviting one to be selected.
            * <p>
            * The performance of this is very important.  If necessary, it may be
            * necessary to run as a separate thread so that the user interface is
            * not delayed.  It is essential that the user be able to type letters at a
            * reasonable speed and not have the keystroke processing held up by
            * previous text.
       public void showMatches( )
           run();
                // First clear the text area
          //results.setText("");
                // Determine the leading characters of the surname that is wanted
                input = namefld.getText();
                // Locate the data for this name, and display each matching item
                //  in the JTextArea ...
                // Example of how to set the data in the popup dialog
          matches.list.setListData(found);
          matches.pack();   // resize the popup
                // set the location of the popup if it is not currently visible
          if ( ! matches.isVisible())
             Dimension sz = matches.getSize();
             Point mouse = getMousePosition();
             Point framepos = getLocation();
             int x=0, y=0;
             if (mouse == null)
                Point pt = results.getLocation();
                x = pt.x + 20 + framepos.x;
                y = pt.y + 20 + framepos.y;
             else
                x = mouse.x - 2 + framepos.x;
                y = mouse.y - 2 + framepos.y;
             matches.setLocation(x,y);
          matches.setVisible(true);
          namefld.requestFocus();
          /** Perform any final processing before closing down.
       public void quitProcessing( )
          // Any closing work.  Then
          System.exit(0);
        public void run()
            ArrayList<String> foundit = new ArrayList<String>();
            System.out.println(input);
            if(input != null)
            Iterator it = members.iterator();
            while(it.hasNext())
               trimember test = (trimember) it.next();
               if (test.last.startsWith(input))
                   foundit.add(test.last +", "+ test.first);
            found = new String[foundit.size()];
            for(int i=0; i<foundit.size();i++)
                found[i] = foundit.get(i);
         /** A window for displaying names and addresses from the data set which
          match the leading characters in namefld.
          <p>
          This will automatically pop down if the user moves the mouse out of the
          window.
          <p>
          It needs code added to it to respond to the user clicking on an item in
          the displayed list. */
       class Chooser extends JWindow
                /** To display a set of names and addresses that match the leading
                characters of the namefld text field. */
          public JList list = new JList();
          Chooser( JFrame parent )
             super( parent );
             Container cpane = getContentPane();
             cpane.addMouseListener( new MouseAdapter()
                public void mouseExited(MouseEvent e)
                   Chooser.this.setVisible(false);
             cpane.add("Center",list);
             list.addListSelectionListener( new ListSelectionListener()
                public void valueChanged(ListSelectionEvent e)
                   Chooser.this.setVisible(false);
                   System.out.println("ValueChanged");
                   // First clear the text area
                   results.setText("");
                   String in = (String) list.getSelectedValue();
                   System.out.println("Selected Value was : "+in);
                   String[] inlf = in.split(", ");
                   System.out.println("inlf[0]:"+inlf[0]+" inlf[1]:"+inlf[1]);
                   results.append("Surname \tFirst \teTag \tMemberNo \tSex \tYOB " +
                           "\tTel \tAddress \t\t\tClub\n");
                   Iterator it = members.iterator();
                   while(it.hasNext())
                       trimember test = (trimember) it.next();
                       if (test.last.equals(inlf[0])&&test.first.equals(inlf[1]))
                           results.append(test.toString()+"\n");
                   namefld.requestFocus();
          public class trimember implements Comparable
           String eTag;
           public String memberNo;
           public String first;
           public String last;
           String gender;
           String yob;
           String tel;
           String addr;
           String club;
           public trimember(String eT, String me, String fi, String la,
                   String ge, String yo, String te, String ad, String cl)
               eTag = eT;
               memberNo = me;
               first = fi;
               last = la;
               gender = ge;
               yob = yo;
               tel = te;
               addr = ad;
               club = cl;         
           //To String method to output string of details
           public String toString()
               return last + "\t" + first + "\t" + eTag + "\t" +
                       memberNo + "\t" + gender + "\t" + yob + "\t"+ tel + "\t" +
                       addr + "\t" + club;
           //Compare and sort on Last name
           public int compareTo(Object o)
               trimember com = (trimember) o;
               int lastCmp = last.compareTo(com.last);
               int firstCmp = first.compareTo(com.first);
               int memCmp = memberNo.compareTo(com.memberNo);
               if (lastCmp == 0 && firstCmp !=0)return firstCmp;
               else if (lastCmp==0&&firstCmp==0)return memCmp;
               else return lastCmp;
    }Edited by: Roger on Nov 3, 2007 11:50 AM

    Please don't cross-post. It is considered very rude to do that here:
    http://forum.java.sun.com/thread.jspa?threadID=5233033&messageID=9953169#9953169

  • Problem with JWindow

    Hi all,
    I have a very important question....
    I created a small application and when i launch it, i'd like to have a JWindow displayed on my screen only during 5 seconds.... So i run my application, my JWindow is displayed during 5 seconds and then the application "really" begins.
    But how do i have to proceed to have my JWindow displayed only during 5 seconds and then close automatically???
    Thanx very much for helping....

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.Timer;
    public class SplashWindow
        public static void main(String[] args)
            JFrame f = new JFrame();
            showSplash(f);
            JPanel panel = new JPanel();
            panel.setBackground(Color.red);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(panel);
            f.setSize(400,300);
            f.setLocationRelativeTo(null);
        private static void showSplash(final Component c)
            JLabel label = new JLabel("hang on, it's coming...", JLabel.CENTER);
            final JWindow w = new JWindow();
            w.getContentPane().add(label);
            w.setSize(200,200);
            w.setLocationRelativeTo(null);
            w.setVisible(true);
            final Timer timer = new Timer(5000, new ActionListener()
                public void actionPerformed(ActionEvent e)
                    w.dispose();
                    c.setVisible(true);
            timer.setRepeats(false);
            timer.start();
    }

  • Jpopupmenu visibility problem with JWindows

    Hello,
    BACKGROUND:
    I am attempting to implement a feature similar to one found in the netbeans IDE for a programming editor I am helping to write. The feature is an autocomplete/function suggestion based on the current word being typed, and an api popup for the selected function.
    Currently a JPopupMenu is used to provide a list of suggested functions based on the current word being typed. EG, when a user types 'array_s' a JPopupMenu pops up with array_search, array_shift, array_slice, etc.
    When the user selects one of these options (using the up/down arrow keys) a JWindow (with a jscrollpane embedded in it) is made visible which displays the api page for that particular function.
    PROBLEM:
    The problem is that when a user scrolls down the JWindow the JPopupmenu disappears so he user cannot select another function.
    I have added a ComponentListener to the JPopupMenu so that when componentHidden is called I can do checks to see if it should be visible and make visible if necessary. However, componentHidden is never called.
    I have added a focuslistener to the JPopupMenu so that when it loses focus I can do the same checks/make visible if necessary. This function is never called.
    I have added a popupMenuListener but this tells me when it is going to make something invisible, not actually when it's done it, so I can't call popup.setVisible(true) from popupMenuWillBecomeInvisible because at that point the menu is still visible.
    Does anyone have any suggestions about how I can scroll through a scrollpane in a JWindow whilst still keeping the focus on a separate JPopupMenu in a separate frame?
    Cheers

    The usual way to do popup windows (such as autocomplete as you're doing) is not to create a JPopupMenu, but rather an undecorated (J)Window. Stick a JList in the popup window for the user to select their choice from. The problem with using a JPopupMenu is just what you're experiencing - they're designed to disappear when they lose focus. Using an undecorated JWindow, you can control when it appears/disappears.
    See this thread for information on how to do this:
    http://forum.java.sun.com/thread.jspa?threadID=5261850&messageID=10090206#10090206
    It refers you to another thread describing how to create the "popup's" JWindow so that it doesn't steal input focus from the underlying text component. Then, further down, it describes how you can forward keyboard actions from the underlying text component to the JWindow's contents. This is needed, for example, so the user can keep typing when the autocomplete window is displayed, or press the up/down arrow keys to select different items in the autocomplete window.
    It sounds complicated, but it really isn't. :)

  • HELP !! XP look and feel ...

    how can i make my frame have an XP look and feel ??????
    please help me in details , cause i haven't done this look and feel thing before ??? thanks in advance ..

    You need to change to the windows LnF which is not the default. The
    following code will do it for you. Note that it will only work if your
    using Windows XP.
    * LookAndFeel.java
    public class LookAndFeel {
        public static final String MAC_CLASS = "com.sun.java.swing.plaf.mac.MacLookAndFeel";
        public static final String METAL_CLASS = "javax.swing.plaf.metal.MetalLookAndFeel";
        public static final String MOTIF_CLASS = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
        public static final String WINDOWS_CLASS = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
        public static final String GTK_CLASS = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
        public static final String KUNSTSTOFF_CLASS = "com.incors.plaf.kunststoff.KunststoffLookAndFeel";
        public static boolean updateLookAndFeel(String currentLookAndFeel, java.awt.Component parent) {
         try {
             javax.swing.UIManager.setLookAndFeel(currentLookAndFeel);
                if(parent != null) {
                    javax.swing.SwingUtilities.updateComponentTreeUI(parent);
         } catch(Exception ex) {
             System.out.println(ex);
                return false;
            return true;
    }To get it to work do the following:
        LookAndFeel.updateLookAndFeel(LookAndFeel.WINDOWS_CLASS, this);where this represents your JWindow or JFrame.
    Hope it helps.
    James.

  • Minimize/Maximize a JWindow

    Hi everyone,
    I created an application that derives JWindow instead of the usual JFrame as the parent class of the application. This works fine but I have a following problems listed below that I have not solved yet.
    1. Is it possible to implement Maximize/Minimize to a JWindow-derived application?
    2. Is it possible to add a Taskbar button that will be displayed in the taskbar area of Windows OS once the application is run?
    Thank you in advance.
    Regards,
    Ferdie

    Hi everyone,
    I created an application that derives JWindow instead
    of the usual JFrame as the parent class of the
    application. This works fine but I have a following
    problems listed below that I have not solved yet.
    1. Is it possible to implement Maximize/Minimize to a
    JWindow-derived application?to the best of my knowledge, no, not directly
    >
    2. Is it possible to add a Taskbar button that will be
    displayed in the taskbar area of Windows OS once the
    application is run?to the best of my knowledge, no, not directly
    I had a problem similar to this before, and what I did was to have a small JFrame that was always behind the JWindow. This causes a button to show up in the taskbar of Windows. also when you have a button on the JWindow for say minimizing it, what you actually do is minimize the JFrame behind it and set the JWindow so its not visible. Then when you want to restore the JWindow from the taskbar, the JWindow is set visible again and the JFrame is placed behind it on the screen. You'll also have to track the user moving the JWindow and move the JFrame behind it accordingly so it is always behind it...
    hope that helps you....

  • JTextField in a FullScreen JWindow jdk1.4

    I have a problem that must have a simple solution I hope.
    I have a JWindow wich I run in fullscreen mode, the contentPane of the JWindow contains a JPanel wich contains JButtons, JLabels and JTextFields I have no problem with the JButtons and JLabels, but the JTextFields get no cursor when clicked and it is therefore impossible to enter text into them.
    I tried using the same JPanel in an ordinary JFrame (not fullscreen) and it worked just as it should.
    What am I missing?
    The JPanel (shortened)
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import javax.swing.*;
    class TheMainMenuPanel extends JPanel
         private BufferedImage background;
         private Graphics2D g2;
         private JButton exitButton=new JButton("Exit Game");
         private JTextField portField=new JTextField(5);
         private JLabel portLabel=new JLabel("Port of game");
         public TheMainMenuPanel()
              Image tmp=new ImageIcon("Graphics\\MainMenuBack.gif").getImage();
              background=ImageUtilities.makeBufferedImage(tmp);
              exitButton.addActionListener(new ActionListener()
                   public void actionPerformed(ActionEvent e)
                        System.exit(0);
    add(portLabel);
         add(portField);
    add(exitButton);
         public void paintComponent(Graphics g)
              g2=(Graphics2D)g;
              g2.drawImage(background,0,0,null);
    I'd be happy for any answer

    I got the same problem with a JTextArea and a JWindow in fullscreen mode.
    How did you got in fullscreen with a JFrame?
    did you found an other solution?
    thanks for your help
    Thomas.

Maybe you are looking for

  • ITunes TV Show conversion

    I have purchased a few TV episodes which I can view on my computer. However, I would like to be able to transfer the files to another protable video device which requires MP4 files. Is it possible to convert the episode to MP4??

  • URGENT!!!!!!!!! rollback in BADI

    Hi, I wanted to know how can we perform ROLLBACK in BAdi's. I am using the BAdi defination -  MB_DOCUMENT_BADI and I want to roll back after i click on POST button in MIGO. The functionality is like - - First I m checking for the tcode eq MIGO. - Sec

  • New house, new ISP and mac not connecting to Internet

    Ok i give up! Just moved to a new apartment, and have cable internet access instead of DSL for the first time. So i have a wirless router from Cablecom, with 4 ethernet ports, but the wireless signal is a bit low so have also connected my Netgear wnd

  • Recursiveness Check in BOM

    How to check the recursive in in bom as system is poping a error  as "Now bom is recursive " while linking with T code CS40. In table level checked in STPO-REKRI for all the plants and there no record with recursive indicator. help me how to track th

  • Has HTMLDB the chance to survive?

    I'm an old mod_plsql fan (Freelancer) and that's the reason that I love this new tool HTMLDB. But we all know these J2EE-fanatics, they were only satisfied when they have a bundle of different servers and a complicated architecture and lot of open so