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

x
?
Solved

button.setPreferredSize error

Posted on 2005-04-22
8
Medium Priority
?
288 Views
Last Modified: 2012-05-05
Not sure why i have an error here, could someone explain?

Button button = new Button("ClickMe");
               button.setPreferredSize(new Dimension(200, 80));
               add(button, BorderLayout.CENTER);
               button.addActionListener(new ActionListener()
                {
                            public void actionPerformed(ActionEvent e)
                            {
                button_actionPerformed(e);
                // logic to handle the button click event
                          }
                });
0
Comment
Question by:pigmentarts
  • 6
  • 2
8 Comments
 
LVL 15

Expert Comment

by:aozarov
ID: 13847826
is this method defined "button_actionPerformed(e);" ?
What is the error message?
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13847830
do you have the right imports?
import java.awt.*;
import java.awt.event.*;
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13847839
replace
button.setPreferredSize with button.setSize
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Accepted Solution

by:
aozarov earned 2000 total points
ID: 13847845
The above should work though you can also do:

Button button = new Button("ClickMe")
{
public Dimension getPreferredSize()
{
return new Dimension(200, 80);
}
};
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13847850
There is no setPreferredSize(..) for AWT components though you have it for Swing componets. (e.g. JButton).
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 13847884
ah thats why then. oopss.

>>button.setPreferredSize with button.setSize  did take away the error but did not change the size of the button.

But you saved yourself with the next bit ;)
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 13847921
going to try n understand the event bit now :(

its four in the mornin so gimmie time >_<
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13848180
Hmm, UK?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month14 days, 8 hours left to enroll

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