Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

This homework problem has me stumped...

Posted on 2012-09-21
8
Medium Priority
?
383 Views
Last Modified: 2012-09-21
I've been working on this one for hours, and yes, this is homework so I'm not lookig for the answer - just a hint maybe? Question: "why is the tooltip text not displayed in this code?"

package myframewithcomponents;

import javax.swing.*;

public class MyFrameWithComponents extends JFrame {
    
    private JButton jbtOK = new JButton( "OK" );
    
    public static void main(String[] args) { 
        // Create a frame and set its properties 
        JFrame frame = new MyFrameWithComponents(); 
        frame.setTitle( "Logic Error" ); 
        frame.setSize( 200 , 100 ); 
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible( true ); }
    
    public MyFrameWithComponents() { 
        jbtOK.setToolTipText( "This is a button" ); 
        add( new JButton( "OK" ) ); }
} 

Open in new window

0
Comment
Question by:tburger88
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Expert Comment

by:Guru Ji
ID: 38422289
try this

JComponent button = new JButton("OK");

// Set tool tip text
button.setToolTipText("tool tip text");
0
 

Author Comment

by:tburger88
ID: 38422299
OH. My. God. Head. Desk.

It wasn't instantiated. Could I be that dumb? Is that the problem?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38422359
It wasn't instantiated.
I might have overlooked something, but everything appears to be instantiated to me. However, I see that in MyFrameWithComponents you are setting the tooltip on the class-level JButton, but then calling the add method with an entirely new and different instance of a JButton. Could that be the issue?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 11

Expert Comment

by:Guru Ji
ID: 38422370
Could be, try that

Also once you add your button to the component/frame you adding, after that at last assign the tooltip
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 38422391
u are not adding the button to the form ur only adding it to the class
0
 
LVL 15

Accepted Solution

by:
Ess Kay earned 1000 total points
ID: 38422395
This adds to class

 private JButton jbtOK = new JButton( "OK" );



also when you add the tooltip use
 form.refresh();
0
 
LVL 11

Assisted Solution

by:Guru Ji
Guru Ji earned 1000 total points
ID: 38422397
so your menthod looks like this now

    public MyFrameWithComponents() {

                JButton button= new JButton("OK");//The JButton name.
                add(button);//Add the button to the JFrame.
              // Set tool tip text
               button.setToolTipText("tool tip text");
}
0
 

Author Closing Comment

by:tburger88
ID: 38422695
THanks you all.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question