JFrame size question
In my JFrame I have setsize(600, 600) and an addComponentListener. I have the getWidth() and getHeight() called in componentResized method. But I am getting values in (608, 634) in return. Can anyone tell me why is that?
Show us the code - a simple working example that shows the problem - and then we can probably help you.
Similar Messages
-
Why I can't get the JFrame size?
HI,
Is anyone to help me find out how to get JFrame size values?
The code as following
package client;
import java.awt.Dimension;
public class IntroFrame extends JFrame {
public IntroFrame() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
private void jbInit() throws Exception {
Dimension frameSize = this.getSize();
// Dimension lblKennamImageSize = lblKennamImage.getSize();
System.out.print("frameSize.height = " + frameSize.height + ", frameSize.width = " + frameSize.width);
// System.out.print("lblKennamImageSize.height = " + lblKennamImageSize.height + ", lblKennamImageSize.width = " + lblKennamImageSize.width);
it give me the result frameSize.height = 0, frameSize.width = 0YES!
Both of you are right, it is my careless mistake.
I will check clearly before post a question later on.
Sorry, I forgot Mark this thread as a question, so I am unable to mark your answers as helpful or correct
Again Sorry about this matter
Thanks
Edited by: fsze88 on Nov 13, 2008 12:45 PM -
hi,
i programmed a program that have a jframe size of 1000x750
and now i want to program using a labtop that have max res of 1280x800 this mean i cant see everything
what is the best way to solve this?
- making the jframe resizable? how can i do that?
- adding a scrollpane? how?
- anything else?Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Insets i = Toolkit.getDefaultToolkit().getScreenInsets(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration());So the available screen area is defined by a rectangle eg,
Rectangle r = new Rectangle(i.left, i.top, screen.width - (i.left + i.right), screen.height - (i.top + i. bottom));Use those values accordingly... ie set the frame size to be the intersection of your intended size and the available screen rectangle. -
Jframe size set as same as monitor screen
can i know how to set jframe size according to monitor screen size ? please help : )
import java.awt.*;
import javax.swing.*;
public class Test3 extends JFrame {
public Test3() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = getContentPane();
setSize(Toolkit.getDefaultToolkit().getScreenSize());
// setExtendedState(JFrame.MAXIMIZED_BOTH);
public static void main(String[] args) { new Test3().setVisible(true); }
} -
JFrame size is not correct althrough specified in code
Hi all,
I've made a GUI, which is being run as a thread since I have incoming/outgoing socket threads also running for an application. It seems that none of the fields are being populated into my JFrame. What is wrong?
import java.net.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
public class Server extends JFrame implements ActionListener, ItemListener
JCheckBox jcbServer=new JCheckBox("Run as Server",false);
JTextField jtfChat=new JTextField("Chat");
JTextField jtfUsername=new JTextField("Username");
JTextArea jtaMessageBox=new JTextArea();
boolean isServer=false;
String message,text,content,sendMessage,user;
int pos;
public Server()
run();
public void run()
int frameWidth=400,frameHeight=150;
Vector<Connection> connections= new Vector<Connection>();
JFrame frame = new JFrame("Chatterbox");
frame.setSize(frameWidth,frameHeight);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(jtfUsername);
frame.add(jcbServer);
frame.add(jtfChat);
frame.add(jtaMessageBox);
jtaMessageBox.setEditable(false);
frame.pack();
frame.setVisible(true);
ServerSocket serverSocket=null;
Connection conn;
boolean listening = true;
if (isServer==true)
try
serverSocket = new ServerSocket(4444);
catch (IOException e)
System.err.println("Could not listen on port: 4444.");
System.exit(-1);
try
while (listening)
Socket socket=serverSocket.accept();
conn=new Connection(socket);
connections.add(conn);
conn.start();
message=conn.getMessage();
if (message.startsWith("/gameMessage"))
content=message.substring(13);
pos=content.indexOf("/");
user=content.substring(pos-1);
text=message.substring(pos+1);
jtaMessageBox.append(user.toString()+ ": "+text);
else if (message.startsWith("/Leaving"))
content=message.substring(9);
pos=content.indexOf("/");
user=content.substring(pos-1);
jtaMessageBox.append(user +" has left");
serverSocket.close();
catch (IOException ex)
public void actionPerformed(ActionEvent ae)
if (ae.getSource()==jcbServer)
if (jcbServer.isSelected()==true)
isServer=false;
else if(jcbServer.isSelected()==false)
isServer=true;
else if (ae.getSource()==jtfChat)
message="/gameMessage"+user+"/"+jtfChat.getText();
else if (ae.getSource()==jtfUsername)
user=jtfUsername.getText();
public void keyReleased(java.awt.event.KeyEvent ke){}
public void keyPressed(java.awt.event.KeyEvent ke){}
public void keyTyped(java.awt.event.KeyEvent ke){}
public void itemStateChanged(java.awt.event.ItemEvent ie) {}
public void mouseMoved(java.awt.event.MouseEvent me){}
public void mouseDragged(java.awt.event.MouseEvent me){}
public void mouseExited(java.awt.event.MouseEvent me){}
public void mouseEntered(java.awt.event.MouseEvent me){}
public void mouseReleased(java.awt.event.MouseEvent me){}
public void mousePressed(java.awt.event.MouseEvent me){}
public void mouseClicked(java.awt.event.MouseEvent me){}
}Many Thanks,
BenWell, to start off with:
Your title on your post has nothing to do with what you are asking in your question,
2nd-your question does not reflect what you ask in your title
Try printing the results out to your console: System.out.println(), I believe you'll find your calls do not return anything to show.
Use your debugger to trace through your project to visually see and find what is happening.
BTW: if you want to fix the displayed size problem with your JFrame: make a JPanel and setPerferredSize to what you want add it to your JFrame and then add all of your other GUI components to your JPanel. When you pack your JFrame, it will take the size of your JPanel. -
IMovie 6 HD - Export Movie Size Question
There is a confusing list of movie export size options that I need to get your clarification about. Some of the selections seem to be similar.
To see what I am referring to go into iMovie HD 6, under the SHARE menu, go to Save Movie For: Expert Settings Export Settings > Select Movie to QuickTime Movie (then hit the options tab to the right > Under the Video Section, select SIZE - note the Export Size Settings - DImensions drop down list. Note there are two sections. The last two items in the top section listed are (exactly worded as) 1280 x 720 HD and 1920 X 1080 HD. In the bottom section the last three entries are HD 1280 x 720 16:9, HD 1440 x 1080 16:9 and HD 1920 x 1080 16:9. What's the difference, for example, between the 1280 x 780 HD and the bottom one HD 1280 x 780 16:9? I ask because my HD camcorder movie footage (shot at 1080i, 29.97, 16:9) with an HV30 exports smooth at 1280x720 HD but jerky at HD 1280 x 780 16:9. They sound the same, but one is jerky and one smooth.
The other question I have is 1440x1040 is 4:3 ratio. But it exports at 16:9 aspect ratio. I don't understand why.Donna:
While I have a lot of video editing experience with an SD digital camcorder, the Canon HV30 HDV cam is new to me. So I am experimenting. That said, footage that will be shot will end up in a couple of places. Some of it will be passed onto my company's web master for posting to the web in some kind of Flash video format. Other video will be used in Keynote presentations as full screen video clips. Others will be used as source video for creating 4x3 SD clips for PowerPoint on a PC by others. So, the video will be used in different formats. (In what format to shoot is another question, but I have concluded (I hope correctly) that I should just shoot HDV 1080i since it seems to be the easiest to deal with for uploading to iMovie6 HD.)
The purpose of my inquiry was to determine what the various selections are used for and what they do. Sometimes the video is jerky, sometimes an identical movie size is smooth (but must be rendered or processed differently). I was only trying to determine why there appeared to be repetative choices in the list of movie sizes as I mentioned in my original post. To be blunt, iMovie 6 HD documentation is spotty at best. The O"Reilly books don't cover the hard parts. -
Problem with ScrollPane and JFrame Size
Hi,
The code is workin but after change the size of frame it works CORRECTLY.Please help me why this frame is small an scrollpane doesn't show at the beginning.
Here is the code:
import java.awt.*;
public class canvasExp extends Canvas
private static final long serialVersionUID = 1L;
ImageLoader map=new ImageLoader();
Image img = map.GetImg();
int h, w; // the height and width of this canvas
public void update(Graphics g)
paint(g);
public void paint(Graphics g)
if(img != null)
h = getSize().height;
System.out.println("h:"+h);
w = getSize().width;
System.out.println("w:"+w);
g.drawRect(0,0, w-1, h-1); // Draw border
// System.out.println("Size= "+this.getSize());
g.drawImage(img, 0,0,this.getWidth(),this.getHeight(), this);
int width = img.getWidth(this);
//System.out.println("W: "+width);
int height = img.getHeight(this);
//System.out.println("H: "+height);
if(width != -1 && width != getWidth())
setSize(width, getHeight());
if(height != -1 && height != getHeight())
setSize(getWidth(), height);
}I create frame here...
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFrame;
public class frame extends JFrame implements MouseMotionListener,MouseListener
private static final long serialVersionUID = 1L;
private ScrollPane scrollPane;
private int dragStartX;
private int dragStartY;
private int lastX;
private int lastY;
int cordX;
int cordY;
canvasExp canvas;
public frame()
super("test");
canvas = new canvasExp();
canvas.addMouseListener(this);
canvas.addMouseMotionListener(this);
scrollPane = new ScrollPane();
scrollPane.setEnabled(true);
scrollPane.add(canvas);
add(scrollPane);
setSize(300,300);
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
public void mousePressed(MouseEvent e)
dragStartX = e.getX();
dragStartY = e.getY();
lastX = getX();
lastY = getY();
public void mouseReleased(MouseEvent mouseevent)
public void mouseClicked(MouseEvent e)
cordX = e.getX();
cordY = e.getY();
System.out.println((new StringBuilder()).append(cordX).append(",").append(cordY).toString());
public void mouseEntered(MouseEvent mouseevent)
public void mouseExited(MouseEvent mouseevent)
public void mouseMoved(MouseEvent mouseevent)
public void mouseDragged(MouseEvent e)
if(e.getX() != lastX || e.getY() != lastY)
Point p = scrollPane.getScrollPosition();
p.translate(dragStartX - e.getX(), dragStartY - e.getY());
scrollPane.setScrollPosition(p);
}...and call here
public class main {
public main(){}
public static void main (String args[])
frame f = new frame();
}There is something I couldn't see here.By the way ImageLoader is workin I get the image.
Thank you for your help,please answer me....I'm not going to even attempt to resolve the problem posted. There are other problems with your code that should take priority.
-- class names by convention start with a capital letter.
-- don't use the name of a common class from the standard API for your custom class, not even with a difference of case. It'll come back to bite you.
-- don't mix awt and Swing components in the same GUI. Change your class that extends Canvas to extend JPanel instead, and override paintComponent(...) instead of paint(...).
-- launch your GUI on the EDT by wrapping it in a SwingUtilities.invokeLater or EventQueue.invokeLater.
-- calling setSize(...) followed by pack() is meaningless. Use one or the other.
-- That's not the correct way to display a component in a scroll pane.
Ah, well, and the problem is that when you call pack(), it retrieves the preferredSize of the components in the JFrame, and you haven't set a preferredSize for the scroll pane.
Please, for your own good, take a break from whatever it is you're working on and go through The Java™ Tutorials: [Creating a GUI with JFC/Swing|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html]
db -
I have a 24-inch iMac, early 2009 model and the internal hard drive has died so am looking to replace it and also upgrade it in the process.
At the moment the broken internal drive was the standard 1TB model that comes with the computer. I have been doing a little bit of research and I'm liking the sound of a hybrid drive as they seem to be a relatively economical was of achieving close to SSD speeds. I've been looking particularly at 'Seagate ST4000DX001 DESKTOP SSHD 4TB SATA 6GB/s NCQ NAND 8GB 64MB HYBRID' for the replacement. I guess my question is if this drive will work in the iMac. Does a hybrid drive present and problems? Also, is there a limit to the maximum size the replacement drive can be? Will 4TB exceed this limit? Lastly, I understand this drive uses SATA III to connect with the computer, which is backwards compatible (I think?) so I'm presuming this will work in my iMac?
Thanks in advance.The hybrid drive will kinda sorta be as fast as an SSD. The newest Seagate Hybrid is quite intelligent about caching the most often used files in flash and is quite an improvement over the first iteration. I used both the first and second generation drives in my 2007 iMac and was quite impressed with their performance…until I installed an SSD. The problem with the hybrids is that they just don’t have enough flash and no matter how intelligent the drive is it is guesswork so sometimes you’ll find the drive access just as pokey as any other 5400 RPM drive and then other times very fast.
For about $200 it is a decent upgrade but with SSD prices having dropped nearly 50% in the last 18 months it is worth considering a smallish internal SSD for the OS and applications and an external drive for data. -
When i resize a JFrame the components it hold remain unchanged until I stop resizing the frame. Then the components conform to the frame size. Is there a way to have the components resize dynamically?
Thank for the answer, that's exactly what I nedded!
-
JScrollPane viewport size question
Hi all,
I've a component that is very large (it has a dinamic height) but its width is always the same (fixed). I need to show this component in a JScrollPane container and only shows the vertical scrollbar. It works fine but when my applications runs, the component inside the JScrollPane (yes..my component) get a different width, which is larger than the original componet's width
I'm using the following code:
JScrollPane scroll = new JScrollPane(myComponent);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);My question is, How I can do for set a fixed width to the JScrollPane (its viewport or its child component) in order to get the correct component width and only allows a dinamic height ?
thanks in advanceimport java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
public class Test3 extends JFrame {
JPanel jp = new JPanel();
JScrollPane jsp = new JScrollPane(jp);
JLabel jl = new JLabel("", JLabel.CENTER);
Random rand = new Random();
public Test3(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = getContentPane();
content.add(jl, BorderLayout.NORTH);
jp.setBorder(BorderFactory.createLineBorder(Color.blue));
jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
content.add(jsp, BorderLayout.CENTER);
JButton jb = new JButton("Random Height");
content.add(jb, BorderLayout.SOUTH);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
int height = rand.nextInt(1000);
jp.setPreferredSize(new Dimension(jsp.getViewport().getWidth(),height));
jsp.getViewport().revalidate();
jl.setText(""+height);
setSize(300,300);
public static void main(String[] args) {new Test3().setVisible(true); }
} -
new to Apple MAC and iPhoto...so....I shot my new camera in jpeg, files are roughly 20mb...then I shot in RAW and after editing, the saved jpegs are ~ 5-10mb and up to 15mb....what happens to make this discrepency? how could my RAW converted jpegs be ~ 1/3 the size of straight out of camera jpegs?
another question...iPhoto is 1.7 gb, my iPhoto Library size it 37gb, but my pictures in iPhoto total 17gb.....is the discrepecy due to stuff like Slideshows I created? Faces just is referring the files right, not making duplicate files?...having trouble wrappping my head around stuff I''m seeing that doesn't add up...
thanksIt's all a bit more complex that that. There is no correlation between file size and the quality of a shot. A well exposed shot of 2 or 3 mb will print just as well as a well exposed shot of 25mb. There is no difference in what gets printed. A poorly exposed shot of 25mb will print like garbage.
It gets worse, we used to suggest a rule of thumb that printing at 300dpi was a reasonable giude to printing quality. Not any more. Printers and cameras have improved, iPhoto books are uploaded at something akin to 150 dpi.
Again, a 3 mb jpeg will print exactly as well as a 30 mb tiff.
Remember, the internet is full of high quality images that weigh in at a lot less than 500kb.
Where file size comes into play is when you're using destructive editing on a lossy format, like Jpeg, and, as I said above, that doesn't come into play in a non-destructive editing system like iPhoto.
The output from the export will - depending on the settings you use - either be smaller or larger than the jepg from a camera. It means very little - unless you're going to go an an edited destructively. -
hello,
My problem is the next one :
-when I use the pack() method on my JFrame it doesn't use the title bar size...so the title is often cut.
-when I use the frame.setSize() method, the size of the frame is dependant of the system and the computer...
How can i solve my problem ?
thanks,
fleur.Hi Zharapic,
Set the preferred size of the JFrames width based on the length of the title string.
Something like this.
//the minimum width of the frame without a title.
int MINIMUM_SIZE = 100;
FontMetrics metrics = jframe.getFontMetrics(jframe.getFont());
int titleOffset = metrics.stringWidth(jframe.getTitle());
//you now have the length of the title so you can set the
//preferred size of the JFrame.
jframe.setPreferredSize(jframe.getHeight(), MINIMUM_SIZE+titleOffset);This way the JFrame should always fit the title when you call pack.
hope this helps.
N35Sy -
Oracle Block Size - question for experts
Hi ,
For years i thought that my system block size was 8K.
Lately due to an HPUX Bug i found that the file system block size is gust .... 1K
(HP DocId: DCLKBRC00006913 fstyp(1m) returns unexpected block size (f_bsize) for VXFS )
My instance is currently 10204 but previously was 7.3 --> 8 --> 8174 --> 10204.
Since its old instance its block size is gust 4kb.
We are planing to create new file system block size of 8k.
The instance size is about 2 TB.
Creating the whole database with 8 kb is impossible since its 24*7 instance.
Do you think that i sould move gust few important tables to a new tablespace with 8k block size , or should i leave it with 4 kb ?
ThanksGiven that your Oracle Database Block_Size (4K) is a multiple of the FileSystem Block_Size (1K), there should be no inherent significant issue, as such.
Yes, it would have been nice to have an 8KB Oracle Database Block_Size but whether you should recreate your FileSystems to 8KB is a difficult question. There would be implications on PreFetch that the OS does and on how the underlying Storage (must be a SAN, I presume) handles those requests.
A thorough test (if you can setup a test environment for 2TB such that it does NOT share the same HW, doesn't complicate PreFetches in the existing SAN) would be well adviced.
Else, check with HP and Veritas support if there are known issues and/or any Desupport plans for this combination ?!
Oracle, obviously, would have issues with Index Key Length sizes if the Block Size is 4KB. Presumably you do not need to add any new indexes with very large keys.
Having said that, you would have read all those posts about how Oracle doesn't (or really does ?) test every different block-size ! However, Oracle had, before 8i, been using 2K and 4K block sizes. Except that the new features (LMT, ASSM etc) may not have been well tested.
Since you upgraded from 7.3 in place without changing the Block_Size, I would venture to say that your database is still using Dictionary Managed and Manual Allocation and Segment Space Management Manual ?
Hemant K Chitale
http://hemantoracledba.blogspot.com -
Player size question for player developers
Question for all player developers:
For media players that you've built or that you've seen out on the web today, how big are they in k? And of that total size, how much code does it take to support each of the service integrations with CDNs, ad servers/networks, analytics services, and content management systems?
I'm interested in total player size, the % of that total devoted to each type of service integration, and the average for an individual service integration.
-SumnerAs I understand it, the new FME (Jan 2008?) will include
support for mp3 audio and much higher audio bitrates, as well as
possibly DRM. -
Canon sRAW to DNG Size Question
Hi,
I shot some images with my Canon 40D set to sRAW. A sample image size is 6.1 MB. In Lightroom 1.3.1, I convert the RAW (.CR2) file to DNG. The resulting DNG file is 6.7MB in size. The DNG Creation settings I used in the conversion were:
JPEG preview: None
Image Conversion Method: Preserve Raw Image
Options: Compressed - ON / Embed Original Raw File - OFF
I was under the impression that DNG format would be smaller than the RAW format.
Is this larger DNG file because my original RAW file was a compressed RAW file (sRAW) and, as a result, the RAW image needs to be uncompressed before it is converted into a DNG file? If the original RAW image was NOT compressed, would I be seeing a reduction if file size after the DNG conversion.
I guess the heart of my questions is this: Will conversion from RAW to DNG only provide a file size reduction if the original RAW file is uncompressed? Is it normal for me to see an increase in size when converting from sRAW to DNG, due to the fact that the original RAW file is a compressed RAW format?
Thanks in advance for your clarification.
SteveThe reason for the larger DNG file is quite complicated, one needs to know some JPEG details. In short, the original sRaw file contains four 15 bit pixel values for two pixels, while the DNG file contains three values per pixel.
The size difference would be much larger if the CR2 file did not contain a 050 KB large thumbnail, which is in the DNG file only between 100 KB abd 200 KB large (approximation).
Plus, the DNG converter fine-tunes the compression; this is not affordable in-camera.
Maybe you are looking for
-
Purchase order output type determination
Hello All, We have a requirement where in we need to trigger custom outout type at the header level on Plant. We have added the plant field at header communication structure but the output type is not getting triggered. Functionals confirmed that all
-
View code view options hidden characters problem
When I turn on the Hidden characters I get extra tab symbols at the end of the line of code. These will somtimes lay on top of or beyond the paragraph symbol. I have tried using other font and font sizes and some do work better than others. It seems
-
Awesome tab completion not working
Hi, I've just upgraded my arch installation to using the awesome WM. However, tab completion refuses to work whe I try launching a program, it just throws me out of the command box. Here is my rc.lua: http://pastebin.com/ihUDiJT7 Any help is much app
-
Is the Fuji X 100 or X100S fully compatible with MacOS10.7.5?
Is the Fuji X 100 or X100S fully compatible with MacOS10.7.5?
-
Are there any techniques for memorizing source code and its place ?
I forget stuff quickly so I have to start everything over and over again . I'm fed up with this ! Please help me ! Thanks .