Hello.
What did you mean by (1,2)?
You will be have to mention the width and height respectively. By doing so you are telling the JVM to set the width to 1 pixel and height to 2 pixels.
Thats a meaningless size.
Syed.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hello.
What did you mean by (1,2)?
You will be have to mention the width and height respectively. By doing so you are telling the JVM to set the width to 1 pixel and height to 2 pixels.
Thats a meaningless size.
Syed.
jps,
I just experimented with what you have said. Its incorrect.
I created one JButton object and added it to a JFrame object.
When I invoked setPreferredSize(new Dimension(1,2)) the button component didn't get displayed.
When I tried new Dimension(40,20) it got displayed.
Let me know if I am still wrong.
Syed.
As small as 1 pixel by two pixels may be, it is still drawn, still present, and still functional./**TestButton.java */ import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.SwingUtilities; public class TestButton extends JPanel implements ActionListener { private static final long serialVersionUID = 1L; public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { TestButton tb = new TestButton(); tb.createAndShowGUI(); } }); } public TestButton() { this.setPreferredSize(new Dimension(40, 40)); String commandTesting = "testing"; JButton button = new JButton(commandTesting); button.setPreferredSize(new Dimension(1,2)); button.addActionListener(this); this.add(button); } public void createAndShowGUI() { JFrame frame = new JFrame("TestButton"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(this); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } @Override public void actionPerformed(ActionEvent ae) { System.out.println(ae.getActionCommand()); } }
--- Update ---
Off topic discussion moved to a new thread