tburger88
asked on
This homework problem has me stumped...
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" ) ); }
}
ASKER
OH. My. God. Head. Desk.
It wasn't instantiated. Could I be that dumb? Is that the problem?
It wasn't instantiated. Could I be that dumb? Is that the problem?
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?
Could be, try that
Also once you add your button to the component/frame you adding, after that at last assign the tooltip
Also once you add your button to the component/frame you adding, after that at last assign the tooltip
u are not adding the button to the form ur only adding it to the class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
THanks you all.
JComponent button = new JButton("OK");
// Set tool tip text
button.setToolTipText("too