ToolTipText on JFrames

Hi,
is there a possibilty of implementing ToolTipText feature directly onto a JFrame ... I am having a JFrame with several shape objects being drawn without having any JPanels involved ... and I want to implement ToolTipText on these Shape objects ... is there a way to do it .. or do we necessarily have to use JPanels ?

Hi
It looks like you have to at least put a JPanel onto the JFrame in order to use a tooltip. I figured that out using Netbeans. Its really nice for making GUI's. It's got a window with all of the properties of whatever Swing or AWT component you need to use (tooltip, name, size, etc). I highly recommend it. Hope this helps.
Regards,
Jay

Similar Messages

  • How can I set the ToolTipText to go away when I pan away

    Normally the toolTipText will go away when you are off the component that the tool tip is related to, but that is not the case when you move the mouse off the application entirely and the buttons are right up against the Container. In that situation the tool tip stays, forever...how annoying. Does anybody know if there is a way to get rid of it, basically to set a timer on it?
    I've read up on the ToolTipManager but I'm not sure what I am suppose to do with it. Am I suppose to instantiate an instance of that class? How does my setToolTipText relate to this ToolTipManager. I thought those methods might be static, but there weren't, so obviously it was intended to be instantiated, but I'm not sure i understand how all that works. Can somebody direct me to some explanation?

    I have a buttonPanel (JPanel) that contains the buttons, this buttonPanel is placed inside a JPanel on the Jframe.
    class ButtonPanel extends JPanel implements ConstantsBase
         private JButton randomButton;
         private JButton solveButton;
         private JButton statisticsButton;
         public ButtonPanel(ActionListener eventHandler)
              super();
              int mazeWidth = CELL_SIZE * GRID_COLS;
              int space = mazeWidth - BPANEL_WIDTH;
              setLayout(new GridLayout());
              setBorder(BorderFactory.createCompoundBorder(
                                            BorderFactory.createLineBorder(Color.black),
                                            BorderFactory.createEtchedBorder()));
              setPreferredSize(new Dimension(
                   BPANEL_WIDTH <= mazeWidth?BPANEL_WIDTH:mazeWidth, BPANEL_HEIGHT));
              if (space >= 0)
                   ((GridLayout)getLayout()).setHgap(space/3);
              else
                   ((GridLayout)getLayout()).setHgap(0);
              // Define JButtons and ToolTips for JButtons
              randomButton = new JButton(RANDOM_BUTTON);
              randomButton.setToolTipText("Re-Randomize Maze");
              randomButton.setMnemonic(KeyEvent.VK_R);
              add(randomButton);
              solveButton = new JButton(SOLVE_BUTTON);
              solveButton.setToolTipText("Solve Maze");
              solveButton.setMnemonic(KeyEvent.VK_S);
              add(solveButton);
              statisticsButton = new JButton(STATISTICS_BUTTON);
              statisticsButton.setToolTipText("Displays Statistical Information");
              statisticsButton.setMnemonic(KeyEvent.VK_T);
              add(statisticsButton);
              // Adding the eventHandlers for each JButton
              randomButton.addActionListener(eventHandler);
              solveButton.addActionListener(eventHandler);
              statisticsButton.addActionListener(eventHandler);
    }

  • Sending event to display the ToolTipText

    HI Coders
    I've extended Jpanel and I draw an Image inside it so that Jpanel is the viewport of the image.
    In usual circumstances when i mouse over the image's viewport the ToolTip execute ,but in my case I need to execute the ToolTipText without actually mouse over the image's viewport, instead I need to press a button which in turn execute the ToolTipText that registered with that image�s viewport.
    this is the code i used but its doesnt work:
    public class NewToolTipTest extends JFrame
        private JLabel l;
        private JButton showTip;
        public NewToolTipTest()
            Image i = Toolkit.getDefaultToolkit().getImage( "someImage.gif" );
            ImageIcon ii = new ImageIcon( i );
            l = new JLabel( ii );
            l.setToolTipText( "Look, it's a ToolTip!" );
            getContentPane().add( l, BorderLayout.CENTER );
            showTip = new JButton( "Show Tip" );
            // Don't give the button a tooltip!  It will replace the
            // tooltip you want to show!
            //showTip.setToolTipText( "Push Me!" );
            showTip.addActionListener( new TipActivate() );
            getContentPane().add( showTip, BorderLayout.SOUTH );
            addWindowListener( new ExitHandler() );
        public static void main( String[] args )
            NewToolTipTest nttt = new NewToolTipTest();
            nttt.pack();
            nttt.setVisible( true );
        private class ExitHandler extends WindowAdapter
            public void windowClosing( WindowEvent event )
                System.exit( 0 );
        private class TipActivate implements ActionListener
            public void actionPerformed( ActionEvent event )
                ToolTipManager theManager = ToolTipManager.sharedInstance();
                MouseEvent toolTipEvent = new MouseEvent( l, MouseEvent.MOUSE_ENTERED,
                        System.currentTimeMillis(), 0, 0, 0, 0, false );
                theManager.mouseMoved( toolTipEvent );
                System.out.println( "ActionEvent launched!" );
    }im using version 1.3 (Swing).
    thanks in advance
    Shay Gaghe

    Hi,
    Here is the code to show the tooltip programmatically where you want :
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TestToolTip extends JPanel {
         Random r =new Random(System.currentTimeMillis());
         JButton b;
         ToolTipManager manager = ToolTipManager.sharedInstance();
         public TestToolTip() {
              manager.setInitialDelay(0);
              setPreferredSize(new Dimension(500,500));
              b= new JButton("Show tooltip at a random location");
              b.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        showToolTip();
         public void showToolTip() {
              int x = r.nextInt(499);
              int y = r.nextInt(499);
              MouseEvent e = new MouseEvent(this, MouseEvent.MOUSE_MOVED, 0, 0,x,y,0,false);
              manager.mouseMoved(e);
         public String getToolTipText(MouseEvent e) {
              return("Position : ("+e.getX()+","+e.getY()+")");
         public static void main(String[] args) {
              JFrame f = new JFrame("Frame");
              TestToolTip t = new TestToolTip();
              f.getContentPane().add(t, BorderLayout.CENTER);
              f.getContentPane().add(t.b, BorderLayout.NORTH);
              f.pack();
              f.setVisible(true);
    }I hope this helps,
    Denis

  • Override the ToolTipText of the JTable with JButton ToolTipTex(pls see msg)

    Hi All,
    Could you please me to solve this problem?
    I have two Icons display on 2 JButtons (2 different ToolTipText for buttons). The Buttons are display on a JPanel. The Panel is display on one of the cell inside JTable. Is it possible that when I move the mouse over each Icon it will displays the ToolTipText of each of the JButton (I am try to replace the ToolTipText of the JTable with the ToolTipText of the JButton when mouse over and when I move the mouse to the next JButton I get a different ToolTipText). The reason I am using the JButton is that in the future I will add actionListener() to do something when the user click on it.
    I have try working with glassPane, addMouseMotionListener, MouseEvent.getPoint(), SwingUtilities.convertPoint, SwingUtilities.getDeepestComponentAt.
    Thank you in advance.
    Note: I am getting the Icons from Object [].

    Hello, the following is one ugly piece of code but I guess that's pretty much what you were after. Just test the tooltip and you'll see that it depends both on the cell and on which of the two buttons is hovered.import javax.swing.*;
    import javax.swing.table.TableCellRenderer;
    import java.awt.*;
    import java.awt.event.MouseEvent;
    public class TestTooltipTable {
         private static class CustomTableCellRenderer implements TableCellRenderer {
              private JButton theLeftButton;
              private JButton theRightButton;
              private JPanel thePanel;
              public CustomTableCellRenderer() {
                   theLeftButton = new JButton("left action");
                   theRightButton = new JButton("right action");
                   thePanel = new JPanel(new GridLayout(1, 2)) {
                        public String getToolTipText(MouseEvent e) {
                             Point p = e.getPoint();
                             Rectangle leftRect = theLeftButton.getBounds();
                             Rectangle rightRect = theRightButton.getBounds();
                             if (leftRect.contains(p)) {
                                  return theLeftButton.getToolTipText();
                             } else if (rightRect.contains(p)) {
                                  return theRightButton.getToolTipText();
                             return " ";
                   thePanel.add(theLeftButton);
                   thePanel.add(theRightButton);
              public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                                                                        boolean hasFocus, int row, int column) {
                   String text = (String)value;
                   theLeftButton.setToolTipText("left action " + text);
                   theRightButton.setToolTipText("right action " + text);
                   return thePanel;
         public static void main(String[] args) {
              final JFrame frame = new JFrame(TestTooltipTable.class.getName());
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              Object[][] data = {{"1", "A"}, {"2", "B"}, {"3", "C"}};
              String[] columnNames = {"Number", "Letter"};
              JTable table = new JTable(data, columnNames) {
                   public String getToolTipText(MouseEvent event) {
                        return super.getToolTipText(event);
              table.setDefaultRenderer(Object.class, new CustomTableCellRenderer());
              ToolTipManager.sharedInstance().registerComponent(table);
              frame.getContentPane().add(new JScrollPane(table));
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        frame.pack();
                        frame.show();
    }

  • JTextField & ToolTipText

    Hello,
    I need some help. I create a JTextField where the content of the text pane have to respect a model. The model is selected by a JComboBox. I want that the ToolTipText shows the skeleton of the selected model.
    Every time I change the selection, I change the content of the ToolTipText but I always see the first text put in the ToolTipText. How can I see the change ?

    I have no idea where the model fits into this
    I have no idea how the text pane fits into thisimport java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JFrame {
      String[] data = {"One","Two","Three"};
      JComboBox jcb = new JComboBox(data);
      JTextField jtf = new JTextField("Something");
      public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Container content = getContentPane();
        content.setLayout(new FlowLayout());
        content.add(jcb);
        jtf.setToolTipText("Some Tooltip");
        content.add(jtf);
        jcb.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            jtf.setToolTipText(jcb.getSelectedItem().toString()+" Tooltip");
        setSize(300, 300);
        show();
      public static void main(String[] args) { new Test(); }
    }

  • Problem with threads in JFrame

    Hy everyone...i have a small problem when i try to insert clock in my JFrame , because all i get is an empty text field.
    What i do is that i create inner class that extends Thread and implements Runnable , but i dont know ... i saw some examples on the intrnet...but they are all for Applets...
    Does any one know how i can implement this in JFrame (JTextField in JFrame).
    Actually any material on threads in JFrame or JPanel would be great....THNX.

    For my original bad thread version, I have rewritten it mimicking javax.swing.Timer
    implementation, reducing average CPU usage to 2 - 3%.
    Will you try this:
    import javax.swing.*;
    import java.awt.*;
    import java.text.*;
    import java.util.*;
    public class SamurayClockW{
      JFrame frame;
      Container con;
      ClockTextFieldW ctf;
      public SamurayClockW(){
        frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        con = frame.getContentPane();
        ctf = new ClockTextFieldW();
        con.add(ctf, BorderLayout.SOUTH);
        frame.setBounds(100, 100, 300, 300);
        frame.setVisible(true);
        ctf.start();
      public static void main(String[] args){
        new SamurayClockW();
    class ClockTextFieldW extends JTextField implements Runnable{
      String clock;
      boolean running;
      public ClockTextFieldW(){
        setEditable(false);
        setHorizontalAlignment(RIGHT);
      public synchronized void start(){
        running = true;
        Thread t = new Thread(this);
        t.start();
      public synchronized void stop(){
        running = false;
      public synchronized void run(){
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        try{
          while (running){
            clock = sdf.format(new Date());
            SwingUtilities.invokeLater(new Runnable(){
              public void run(){
                setText(clock);
            try{
              wait(1000);
            catch (InterruptedException ie){
              ie.printStackTrace();
        catch (ThreadDeath td){
          running = false;
    }

  • Can not refresh JFrame

    I am new to Java programming however I have undertaken a project to build a serial communication application using J2SE 1.4 w/javax.comm API. I am having a problem in which I detect a button click with action listener and post a JOptionPane message. Once the JOptionPane is closed I execute the desired task however the pane leaves a grey block overlaying the JFrame. I have been unable to figure out how to repaint the JFrame. Can anyone give me suggestions?
    Thanks
    D :-)

    A more active example:
    if (JOptionPane.showConfirmDialog(null, "Are you
    u sure?",
    "Are you sure?", JOptionPane.YES_NO_OPTION) ==
    N) == 0) {
    Thread t = new Thread(new Runnable() {
    public void run() {
    // Do your work in here!
    t.start();
    }This will leave the JFrame completely free to do
    whatever else it wants, so if you want it to do
    nothing, you may want to write a 'disableFrame()'
    method which disables everything, and perhaps stick a
    JProgressBar at the bottom to show that something's
    going on. This needs to be controlled via the 'run()'
    method.
    Let me know if this helps.
    RichardThanks Richard.
    Do I have to stop the thread explicitly. The task looks for a serial event.

  • Need to convert JApplet to JFrame

    I need to write code for where I have 60 balls bouncing around inside a window. The client will then be able to select a button and it will pull out a ball with the number 1-60 written on it. The user will be able to do this up to 7 times. Each time it is done the past numbers that have already appeared can not reappear. What I am stuck on right now is geting my balls into a JFrame. Can anyone give advice or show how to. I currently have my 60 balls running in a JApplet. Here is the JAVA code and the HTML code. Thanks!
    Here is the JAVA code
    import java.awt.*;
    import java.applet.*;
    import java.util.*;
    import javax.swing.*;
    class CollideBall{
    int width, height;
    public static final int diameter=20;
    //coordinates and value of increment
    double x, y, xinc, yinc, coll_x, coll_y;
    boolean collide;
    Color color;
    Graphics g;
    Rectangle r;
    //the constructor
    public CollideBall(int w, int h, int x, int y, double xinc, double yinc, Color c){
    width=w;
    height=h;
    this.x=x;
    this.y=y;
    this.xinc=xinc;
    this.yinc=yinc;
    color=c;
    r=new Rectangle(150,80,130,90);
    public double getCenterX() {return x+diameter/2;}
    public double getCenterY() {return y+diameter/2;}
    public void alterRect(int x, int y, int w, int h){
    r.setLocation(x,y);
    r.setSize(w,h);
    public void move(){
    if (collide){  
    double xvect=coll_x-getCenterX();
    double yvect=coll_y-getCenterY();
    if((xinc>0 && xvect>0) || (xinc<0 && xvect<0))
    xinc=-xinc;
    if((yinc>0 && yvect>0) || (yinc<0 && yvect<0))
    yinc=-yinc;
    collide=false;
    x+=xinc;
    y+=yinc;
    //when the ball bumps against a boundary, it bounces off
    if(x<6 || x>width-diameter){
    xinc=-xinc;
    x+=xinc;
    if(y<6 || y>height-diameter){
    yinc=-yinc;
    y+=yinc;
    //cast ball coordinates to integers
    int x=(int)this.x;
    int y=(int)this.y;
    //bounce off the obstacle
    //left border
    if(x>r.x-diameter&&x<r.x-diameter+7&&xinc>0&&y>r.y-diameter&&y<r.y+r.height){
    xinc=-xinc;
    x+=xinc;
    //right border
    if(x<r.x+r.width&&x>r.x+r.width-7&&xinc<0&&y>r.y-diameter&&y<r.y+r.height){
    xinc=-xinc;
    x+=xinc;
    //upper border
    if(y>r.y-diameter&&y<r.y-diameter+7&&yinc>0&&x>r.x-diameter&&x<r.x+r.width){
    yinc=-yinc;
    y+=yinc;
    //bottom border
    if(y<r.y+r.height&&y>r.y+r.height-7&&yinc<0&&x>r.x-diameter&&x<r.x+r.width){
    yinc=-yinc;
    y+=yinc;
    public void hit(CollideBall b){
    if(!collide){
    coll_x=b.getCenterX();
    coll_y=b.getCenterY();
    collide=true;
    public void paint(Graphics gr){
    g=gr;
    g.setColor(color);
    //the coordinates in fillOval have to be int, so we cast
    //explicitly from double to int
    g.fillOval((int)x,(int)y,diameter,diameter);
    g.setColor(Color.white);
    g.drawArc((int)x,(int)y,diameter,diameter,45,180);
    g.setColor(Color.darkGray);
    g.drawArc((int)x,(int)y,diameter,diameter,225,180);
    public class BouncingBalls extends Applet implements Runnable {
    Thread runner;
    Image Buffer;
    Graphics gBuffer;
    CollideBall ball[];
    //Obstacle o;
    //how many balls?
    static final int MAX=60;
    boolean intro=true,drag,shiftW,shiftN,shiftE,shiftS;
    boolean shiftNW,shiftSW,shiftNE,shiftSE;
    int xtemp,ytemp,startx,starty;
    int west, north, east, south;
    public void init() {  
    Buffer=createImage(getSize().width,getSize().height);
    gBuffer=Buffer.getGraphics();
    ball=new CollideBall[MAX];
    int w=getSize().width-5;
    int h=getSize().height-5;
    //our balls have different start coordinates, increment values
    //(speed, direction) and colors
    for (int i = 0;i<60;i++){
    ball=new CollideBall(w,h,50+i,20+i,1.5,2.0,Color.white);
    /* ball[1]=new CollideBall(w,h,60,210,2.0,-3.0,Color.red);
    ball[2]=new CollideBall(w,h,15,70,-2.0,-2.5,Color.pink);
    ball[3]=new CollideBall(w,h,150,30,-2.7,-2.0,Color.cyan);
    ball[4]=new CollideBall(w,h,210,30,2.2,-3.5,Color.magenta);
    ball[5]=new CollideBall(w,h,360,170,2.2,-1.5,Color.yellow);
    ball[6]=new CollideBall(w,h,210,180,-1.2,-2.5,Color.blue);
    ball[7]=new CollideBall(w,h,330,30,-2.2,-1.8,Color.green);
    ball[8]=new CollideBall(w,h,180,220,-2.2,-1.8,Color.black);
    ball[9]=new CollideBall(w,h,330,130,-2.2,-1.8,Color.gray);
    ball[10]=new CollideBall(w,h,330,10,-2.1,-2.0,Color.gray);
    ball[11]=new CollideBall(w,h,220,230,-1.2,-1.8,Color.gray);
    ball[12]=new CollideBall(w,h,230,60,-2.3,-2.5,Color.gray);
    ball[13]=new CollideBall(w,h,320,230,-2.2,-1.8,Color.gray);
    ball[14]=new CollideBall(w,h,130,300,-2.7,-3.0,Color.gray);
    ball[15]=new CollideBall(w,h,210,90,-2.0,-1.8,Color.gray);*/
    public void start(){
    if (runner == null) {
    runner = new Thread (this);
    runner.start();
    /* public void stop(){
    if (runner != null) {
    runner.stop();
    runner = null;
    public void run(){
    while(true) {
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    try {runner.sleep(15);}
    catch (Exception e) { }
    //move our balls around
    for(int i=0;i<MAX;i++)
    ball[i].move();
    handleCollision();
    repaint();
    boolean collide(CollideBall b1, CollideBall b2){
    double wx=b1.getCenterX()-b2.getCenterX();
    double wy=b1.getCenterY()-b2.getCenterY();
    //we calculate the distance between the centers two
    //colliding balls (theorem of Pythagoras)
    double distance=Math.sqrt(wx*wx+wy*wy);
    if(distance<b1.diameter)
    return true;
    return false;
    private void handleCollision()
    //we iterate through all the balls, checking for collision
    for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
    if(i!=j)
    if(collide(ball[i], ball[j]))
    ball[i].hit(ball[j]);
    ball[j].hit(ball[i]);
    public void update(Graphics g)
    paint(g);
    public void paint(Graphics g)
    gBuffer.setColor(Color.lightGray);
    gBuffer.fillRect(0,0,getSize().width,getSize().height);
    gBuffer.draw3DRect(5,5,getSize().width-10,getSize().height-10,false);
    //paint our balls
    for(int i=0;i<MAX;i++)
    ball[i].paint(gBuffer);
    g.drawImage (Buffer,0,0, this);
    Here is the HTML code
    <html>
    <body bgcolor="gray">
    <br><br>
    <div align="center">
    <applet code="BouncingBalls.class" width="1000" height="650"></applet>
    </div>
    </body>
    </html>

    In the future, Swing related questions should be posted in the Swing forum.
    First you need to convert your custom painting. This is done by overriding the paintComponent() method of JComponent or JPanel. Read the Swing tutorial on [Custom Painting|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html].
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the [Code Formatting Tags|http://forum.java.sun.com/help.jspa?sec=formatting], so the posted code retains its original formatting.

  • Problem with Paining in a Panel in a JFrame.

    So I can paint directly on a JFrame, and I can paint on a class that extends Panel, and put the Panel on a JFrame. But if I try to Repaint the Panel it won't show on the JFrame. Do I have to do anything to the JFrame to show the changes to the objects inside as well?

    I'm not sure if you've done this, but don't change the paint method when using Swing components, use paintComponent instead. By default, the JFrame will paint its children. Just remember whenever overriding any of the paintComponent methods to call super.paintComponent(g) first.

  • Problem with IconImage for JFrame

    If I create an BufferedImage by ImageIO.read for example and then call getScaledInstance on this image and set the scaled Image to a JFrame as the IconImage (via setIconImage(Image image)), the application hangs.
    Has anyone else this problem?

    ok ok, i read it and now think that this is a sscce:
    import java.awt.Image;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    public class Start
         public static void main(String[] args)
              final JFrame frame = new JFrame();
              final Image image, imageScaled;
              try
                   image = ImageIO.read(new File("test.png"));
                   imageScaled = image.getScaledInstance(8, 8, Image.SCALE_DEFAULT);
                   frame.add(new JLabel(new ImageIcon(image)));
                   //frame.setIconImage(image); works
                   frame.setIconImage(imageScaled); // works not
                   frame.pack();
                   frame.setVisible(true);
              catch (IOException e)
                   System.err.println(e.getMessage());
                   e.printStackTrace(System.err);
    }

  • Problem with display of JFrame

    I have a run opperation in which i call a method that creates a j frame and displays it. all the j frame is used for is displaying the text "adding sample data...". It works fine when I have my main window open but when I have my layout editor open, the JFrame shows up grayed out. It clears after my samples are added. I have no Idea why it wont display correctly and I was just wondering if you had any ideas as to what whould cause this to happen. Thanks

    I can't be sure without seeing your code, or without more information about what it is your doing, but the problem could be threading. Is the JFrame that's showing up grayed out just supposed to tell the user to basically "please wait while I do something", and then dissapear after it's done working? If so, you should probably use a JDialog. In any case, try wrapping the code that opens the window in this:
    Thread opener new Thread(new Runnable(){
         public void run()
              // ... put your code that opens the window in here.  such as myFrame.setVisible(true);
    opener.start();

  • Problem with backspace on JFrame

    Hello,
    I have a problem on a JFrame. Indeed, I add a keyListener to the frame, but the "Bakcspace" don't work. There is anything when a I press on Backspace (with KeyTyped, KeyReleased and KeyPressed). All other keys are working.
    Thanks.

    the solution of the problem is :
    Version note: This page reflects the focus API introduced in released 1.4. As of that release, the focus subsystem consumes focus traversal keys, such as Tab and Shift Tab. If you need to prevent the focus traversal keys from being consumed, you can call
    component.setFocusTraversalKeysEnabled(false)
    on the component that is firing the key events. Your program must then handle focus traversal on its own. Alternatively, you can use a KeyEventDispatcher to pre-listen to all key events. The focus page (in the Creating a GUI with JFC/Swing trail) has detailed information on the focus subsystem.

  • Problem with jDialog in a JFrame

    Hello to everyone...i'm newby java GUI developer, and i've got a problem with a JDialog within a JFrame...
    I made a JFrame which creates a new customized JDialog in his contructor, like this:
    MioJdialog dlg = new MioJdialog(this, true);
    dlg.setVisible(true);
    ...The "MioJdialog" class store his JFrame parent under a private attribute, in this way:
    class MioJdialog {...
    private Frame parent;
    public MioJdialog (Frame parent, boolean modal){
        this.parent=parent;
    ....}and here's the problem: when i try to close the parent JFrame with a command like this:
    parent.dispose();
    ( in order to close the whole window), sometimes happens that the JFrame is still visible on the screen...and i don't know why...
    got some hints?
    thanks to everyone!
    Edited by: akyra on Jan 14, 2008 4:36 AM
    Edited by: akyra on Jan 14, 2008 4:37 AM
    Edited by: akyra on Jan 14, 2008 4:37 AM

    If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
    http://homepage1.nifty.com/algafield/sscce.html
    Don't forget to use the "Code Formatting Tags", so the posted code retains its original formatting.
    http://forum.java.sun.com/help.jspa?sec=formatting

  • Problem with setContentPane() in JFrame class

    I recently discovered a problem with the setContentPane method in the JFrame class. When I use setContentPane(Container ..), the previously existing contentPane remains in the stack. I have tried nullifying getContentPane(), and all manner of things, but, each time I use setContentPane, I have another instance of a JPanel in the stack.
    I'm using code similar to setContentPane(new CustomJPanel()); and each time the user changes screens, and a similar call to that is made, the old CustomJPanel instance remains in the stack. Can anyone suggest a way around this? On their own the panels do not take up very much memory, but after several hours of usage, they will build up.

    I tried what you suggested; it only resulted in a huge performance decrease. The problem with memory allocation is still there.
    Here is the method I use to switch screens in my app:
    public static void changeScreen (JPanel panel){
              try{
                   appFrame.setTitle("Wordinary : \""+getTitle()+"\"");
                   appFrame.setContentPane(panel);
                   appFrame.setSize(appFrame.getContentPane().getPreferredSize());     
                   appFrame.getContentPane().setBackground(backColour);
                   for (int i = 0; i < appFrame.getContentPane().getComponents().length; i++)
                        appFrame.getContentPane().getComponents().setForeground(textColour);
                   //System.out.println("Background colour set to "+backColour+" text colour set to "+textColour);
                   appFrame.validate();
              catch (Exception e){
                   //System.out.println("change");
                   e.printStackTrace();
    And it is called like this:
    changeScreen(new AddWordPanel());The instantiation of the new instance is what is causing the memory problems, but I can't think of a way around it.

  • Problem with JPanel in JFrame

    hai ashrivastava..
    thank u for sending this one..now i got some more problems with that screen .. actually i am added one JPanel to JFrame with BorderLayout at south..the problem is when i am drawing diagram..the part of diagram bellow JPanel is now not visible...and one more problem is ,after adding 6 ro 7 buttons remaing buttons are not vissible..how to increase the size of that JPanel...to add that JPanel i used bellow code
    JFrame f = new JFrame();
    JPanel panel = new JPanel();
    f.getContentPane().add(BorderLayout.SOUTH, panel);

    Hi
    JFrame f = new JFrame();
    JPanel panel = new JPanel();
    // Add this line to ur code with ur requiredWidth and requiredHeight
    panel.setPreferredSize(new Dimension(requiredWidth,requiredHeight));
    f.getContentPane().add(BorderLayout.SOUTH, panel);
    This should solve ur problem
    Ashish

Maybe you are looking for

  • K8N Neo4 Platinum (PCB 1.0) and AMD 64 3800+ X2

    Help! I have a K8N Neo4 Platinum (PCB 1.0) and it had an AMD 64 3200+ single core CPU. Now I've upgraded to an AMD 64 3800+ X2 dual core but the BIOS and MS Vista are seeing only the one core. The BIOS is at the latest version - 1.D. Whats' going on?

  • Monitoring with Blackmagic hardware

    I use a Blackmagic Decklink SDI in Adobe Premiere, but it doesn't show up in Encore, even though the video output preferences window looks very similiar.  How do you preview on a broadcast monitor?

  • Word document disappear after saving

    I was working on a wrod document and after i saved the document i went to close it. After closing the document i went to submit it via email and the paper is nowhere on my computer. My recent files says i was not on word for the last 2 days! Can i fi

  • More than one, OneToOne relation gives problem

    This is my bean class structure @Entity @Table(name="TBL_PRODUCTS") public class TblProducts implements Serializable    @Id    @Column(name="PRODUCT_ID")       private BigDecimal productId;    @Column(name="PRODUCT_NAME")       private String product

  • MacBook Pro 15" early 2008 Hard Drive Upgrade & More

    I have a MacBook Pro early 2008 15" and would like to upgrade the hard drive to a 1TB but my local Mac Approved Tech Store is advising against it.  They suggest 500GB.  I have taken up photography and have large jpeg files to store.  Also will this m