jframe

JLabel setLocation not working?

依然范特西╮ 提交于 2019-12-17 21:13:12
问题 Here is the code I have written: super("Add contact"); setLayout(new FlowLayout()); IPAddress = new JLabel("IP Address"); IPAddress.setLocation(1000, 100); ImageIcon ii=new ImageIcon(getClass().getResource("Add.png")); JLabel image = new JLabel(ii); image.setSize(100, 100); image.setLocation(500, 100); add(image); add(IPAddress); setSize(500,150); } 回答1: That is correct. The layout manager is responsible for setting the location of a component based on the rules of the layout manager. So in

Background image JFrame with content

柔情痞子 提交于 2019-12-17 21:09:10
问题 I have a JFrame with BorderLayout , there are panels on all sides (North, East ,...). In the panels there are labels and buttons mostly. Now I want the frame to have a background image, some research told me that i had to change the content pane of my frame. When I try this however, the content gets put in the background and isn't visible. Also, I don't know how to resize the image if the frame is resized. Is there an easy fix for this or will I have to rework most of my code? 回答1: put JPanel

Thread.sleep() stopping my paint?

拟墨画扇 提交于 2019-12-17 21:01:45
问题 I'm making a program that is trying to animate a card moving across the screen as if you actually drew it from a desk. Here is the code for the animating: public void move(int x, int y) { int curX = this.x; //the entire class extends rectangle int curY = this.y; // animate the movement to place for (int i = curX; i > x; i--) { this.x = i; } this.x = x; this.y = y; } this rectangle object is inside of a panel inside of a jframe. for repainting the panel, i have this: public void run() { while

My JFrame always becomes a few pixels too big.

十年热恋 提交于 2019-12-17 20:53:50
问题 I am working on this game in Java, and I just rewrote all my window related code from being based on java.awt to javax.swing. Soon after, I realized that things were a bit more complicated now, and so i did some research and and found out how to draw things, how to set the size of a JFrame, etc. But for some reason, the size of my JFrame always goes 10 pixels beyond the size I've specified it to become. In this case, I wanted it to be 640 by 640 pixels. Here's my code: package chrononaut;

Java JFrame background color not working

China☆狼群 提交于 2019-12-17 20:49:22
问题 I tried using: frame1.getContentPane().setBackground(Color.yellow); But it is not working. Can anyone help me? import java.awt.*; import java.awt.Color; public class PlayGame { public static void main(String[] args) { GameFrame frame1 = new GameFrame(); frame1.getContentPane().setBackground(Color.yellow); // Set Icon Image icon = Toolkit.getDefaultToolkit().getImage("image/poker_icon.gif"); frame1.setIconImage(icon); frame1.setVisible(true); frame1.setSize(600, 700); frame1.setTitle("Card

In JAVA, changing resolution with setDisplayMode for fullscreen application

邮差的信 提交于 2019-12-17 20:42:07
问题 I am a beginner int the JAVA language and is trying to learn how to create full screen applications. I am trying to create a simple application where when run, displays a full screen with blue back ground and a simple line of text in the center of the screen( it starts at position 400x300). The resolution of the application is set to 800x600. I am running the code on a MacbookAir, running OSX Lion, with a screen resolution of 1440x900. The problem is, despite getting a blue background as I

True Full Screen JFrame/Swing Application in Mac OSX

无人久伴 提交于 2019-12-17 20:33:44
问题 I'm working on application and I'm making the GUI with Swing. I would like my application to be fullscreen. I can easily set the size of the window however I have not been able to make the application truly fullscreen (IE With the apple menu bar and dock hidden). All the answers I have found online don't seem to work for me. I'm new to Java so any help is appreciated. frame = new JFrame("Test"); frame.setTitle("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel emptyLabel =

printing a 2 pages of jframe in java

风流意气都作罢 提交于 2019-12-17 20:31:27
问题 i would like to print a jframe that contain a lot of textfield and buttons that contain a data. i want to print this jframe by clicking a Print jbutton. i tried this code. protected void print() { PrinterJob job = PrinterJob.getPrinterJob(); if(job.printDialog()){ try { job.setPrintable(new Printable() { @Override public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { if(pageIndex == 0){ Graphics2D g2d = (Graphics2D)graphics; g2d.translate

How can i set a jFrame to be always on top and focuse enabled until it is closed?

风格不统一 提交于 2019-12-17 20:07:03
问题 There are two different Frames in my program and the second one open when i click the jButton is the first frame,so when the second frame is opened, I want the second frame to be always on top and focused until it is close. user can't be allowed to do anything in the first window until the second window is closed. how can i do this? 回答1: JFrame frame = new JFrame (); frame.setAlwaysOnTop (true); If you want frame to be always focused, you probably need to use modal dialog instead of JFrame:

JFrame On Close Operation

随声附和 提交于 2019-12-17 19:58:43
问题 I was wondering if there is a way, by clicking on the "X", to let the program perform some code before closing the JFrame. The setDefaultCloseOperation() method takes only an integer. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 回答1: You might be interested in using a WindowListener. The WindowListener tutorial. 回答2: this.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ int i=JOptionPane.showConfirmDialog(null, "Seguro que quiere salir?"); if(i==0) System