Results 1 to 8 of 8
Thread: [Help] setSize work wrong ???
- 11-04-2009, 12:00 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 6
- Rep Power
- 0
[Help] setSize work wrong ???
I'm trying to make a tiny application : click into a button and JFrame will resize
The result is : width 500 height 920 :confused: .Java Code:private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { setSize(500,[COLOR="DarkRed"]1000[/COLOR] ); /// apply for Frame System.out.println("width" + getWidth()); System.out.println("height " + getHeight()); }
I cannot understand why i setHeight 1000 but result is 920 . Anybody can help me ???
-
I usually use setPreferredSize(new Dimension(x, y)) and I usually call it on something other than the JFrame such as the JFrame's contentPane. I then call pack() on the JFrame to get it to listen to my new preferred size.
- 11-04-2009, 01:15 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 6
- Rep Power
- 0
I tried
But result didn't change : height 920 :(Java Code:setPreferredSize(new Dimension(500, 1000)); pack();
-
It looks as if you called preferred size on the jframe, not its content pane. Truthfully, it's hard to tell what you're doing without seeing a small compilable program that demonstrates your problem, a minimal working example or SSCCE. I suggest you consider creating this and posting this.
- 11-04-2009, 04:14 PM #5
Member
- Join Date
- Nov 2009
- Posts
- 6
- Rep Power
- 0
Here is it . It was creat by NeatBean IDE
So strange bc when i set Height small it work perfect , but when it large (out of screen ) it work wrong :(Java Code:import java.awt.Dimension; public class MainFrame extends javax.swing.JFrame { public MainFrame() { initComponents(); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jButton1 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosed(java.awt.event.WindowEvent evt) { formWindowClosed(evt); } }); jButton1.setText("New"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(129, 129, 129) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(148, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(118, 118, 118) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(105, Short.MAX_VALUE)) ); pack(); }// </editor-fold> [COLOR="Olive"] private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { /* setSize(500,1000); System.out.println(getHeight()); */ setPreferredSize(new Dimension(500, 1000)); pack(); System.out.println(getHeight()); } [/COLOR] public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new MainFrame().setVisible(true); } }); } SecondFrame a; // Variables declaration - do not modify private javax.swing.JButton jButton1; // End of variables declaration }
- 11-04-2009, 05:05 PM #6
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,158
- Rep Power
- 5
Well, maybe that is a clue, it doesn't make sense to make the frame larger than the screen.but when it large (out of screen ) it work wrong
My screen resolution is 1024 x 768 and the size seems to max out a 1036 x 780, so it seems to allow 12 extra pixels. I don't know what the significance of that is.
- 11-05-2009, 08:51 AM #7
Member
- Join Date
- Nov 2009
- Posts
- 6
- Rep Power
- 0
Maybe that's correct clue. Thanks Fubarable & camickr
- 11-05-2009, 09:30 AM #8
Similar Threads
-
what is wrong?
By pinguxxx in forum Advanced JavaReplies: 3Last Post: 07-15-2009, 12:33 PM -
What am I doing wrong??
By NoNickName in forum New To JavaReplies: 3Last Post: 04-23-2009, 11:04 PM -
what am i doing wrong here??
By tornbacchus in forum New To JavaReplies: 19Last Post: 04-16-2009, 03:54 AM -
what's wrong?
By rayda in forum New To JavaReplies: 3Last Post: 04-14-2009, 09:07 PM -
what wrong
By pro85 in forum New To JavaReplies: 3Last Post: 02-09-2009, 01:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks