jframe

Java: Difference between the setPreferredSize() and setSize() methods in components

那年仲夏 提交于 2019-11-26 00:16:43
问题 Ok, I read the Java Documentation and I just can\'t figure out what is the main difference between those two methods. Sometimes I used setSize(), sometimes setPreferredSize(), sometimes one does what I want, sometimes the other. So, what is the main difference between the two? Which one should I use for JFrames and JPanels ? Thanks 回答1: The short answer is: it's complicated. The slightly longer answer is: use setSize() if your component's parent has no layout manager, and setPreferredSize()

Setting background images in JFrame

拟墨画扇 提交于 2019-11-25 23:42:51
问题 Are any methods available to set an image as background in a JFrame ? 回答1: There is no built-in method, but there are several ways to do it. The most straightforward way that I can think of at the moment is: Create a subclass of JComponent. Override the paintComponent(Graphics g) method to paint the image that you want to display. Set the content pane of the JFrame to be this subclass. Some sample code: class ImagePanel extends JComponent { private Image image; public ImagePanel(Image image)

JComponents not showing up with picture background?

╄→гoц情女王★ 提交于 2019-11-25 22:58:35
问题 My components are not showing up. How do I fix this? Code: import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.*; public class login implements ActionListener{ JTextField gusername; JTextField gpassword; static String username; static String password; void logini() throws IOException { JFrame window = new JFrame(\"Login\

The Use of Multiple JFrames: Good or Bad Practice? [closed]

喜你入骨 提交于 2019-11-25 22:50:41
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . I\'m developing an application which displays images, and plays sounds from a database. I\'m trying to decide whether or not to use a separate JFrame to add images to the database from the GUI. I\'m just wondering whether it is good practice to use multiple JFrame windows?

Program not accessing method paintComponent() of extended JPanel class

假如想象 提交于 2019-11-25 22:46:56
问题 This is the JFrame package client.connection; import java.awt.Dimension; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import javax.swing.JFrame; class DrawFrameRemoteControl extends JFrame { private DrawPanelRemoteControl imagePanel; private ClientRemoteControlConnection clientRemoteControlConnection; private ObjectInputStream clientInputStream; private ObjectOutputStream clientOutputStream; private Dimension imageDimension; private Dimension serverDimension; public

How to programmatically close a JFrame

你离开我真会死。 提交于 2019-11-25 22:44:56
问题 What\'s the correct way to get a JFrame to close, the same as if the user had hit the X close button, or pressed Alt + F4 (on Windows)? I have my default close operation set the way I want, via: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); It does exactly what I want with the aforementioned controls. This question isn\'t about that. What I really want to do is cause the GUI to behave in the same way as a press of X close button would cause it to behave. Suppose I were to extend

Something seems wrong with the layout, JButton showing unexpected behaviour at resize of the window

这一生的挚爱 提交于 2019-11-25 22:05:24
问题 JRE Version 1.7 Update 3 EXPECTED BEHAVIOUR As I run the program, it works as expected, everything works smoothly. As when I click on STOP JButton the animation stops and the text on the same JButton changes to START . Now when i click on BALL COLOUR JButton , the colour of the BALL changes, as well as the colour of the BALL COLOUR JBUTTON , also changes, to that of the BALL . This whole behaviour works if I run my application as is without resizing. UNEXPECTED BEHAVIOUR But when i RESIZE my

Swing: Obtain Image of JFrame

天涯浪子 提交于 2019-11-25 21:46:07
问题 How do I obtain a java.awt.Image of a JFrame? I want to obtain a screen shot of a JFrame (for later use within my application). This is presently accomplished using the robot to take a screen shot specifying the coordinates and dimensions of the JFrame involved. However, I believe that there is a better way: Swing components, by default, render themselves as images into a double buffer prior to painting themselves onto the screen. Is there a way to obtain these images from the component? 回答1: