jframe

Java: How can I bring a JFrame to the front?

半腔热情 提交于 2019-12-18 09:02:55
问题 I am currently waiting for a very important announcement and I have created a simple application to check every 30 minutes whether the announcement was made or not When the announcement is made, I want a window to pop up and inform me about it. The window is just a simple JFrame that has some text in it. I have a class called Announcement. Inside this class I define another class for the frame called Form, so I have something like this: class Form{ public Form(){ //create frame and show it

Draw text with graphics object on JFrame

守給你的承諾、 提交于 2019-12-18 07:42:24
问题 I am an avid programmer but today is my first Java lesson. public void Paint (Graphics g) { if(g instanceof Graphics2D) { Graphics2D g2d = (Graphics2D)g; g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } g.drawString("This is gona be awesome", 200, 200); } With the above code, I want to write a sentence on the window but it never writes. What am I doing wrong? Edit: Never mind - Paint must be paint. I apologize profusely. 回答1: In the given

How do I hide the current JPanel and show a new one with a button in Java?

◇◆丶佛笑我妖孽 提交于 2019-12-18 06:57:31
问题 I unfortunately have to use multiple windows in this program and I don't think CardLayout is going to work because I can't have any buttons constant between the different layouts. So I'm trying to code a button to hide the present JPanel (thePanel) and show a new one (thePlacebo). I'm trying to hide thePanel in an ActionListener like this: frame.getContentPane().remove(thePanel); I thought this would work, but it just freezes my program as soon as I hit the button. Here's a chunk of the code

how can I scroll my JFrame using the JScrollbar?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 05:51:34
问题 I have a problem. I have a JFrame with some JTextFields, JLabels, Jlists & JButtons now the contents of my frame is more than the screen area so I want to attach a JScrollBar to my JFrame but my srollbar does not work. So, can anyone please guide me on how I can scroll my JFrame using the JScrollbar? 回答1: Put all the components in one panel (instead of in the JFrame) Add this panel to a JScrollPane Add the JScrollPane to your frame. I should be something like: JPanel container = new JPanel();

how can I scroll my JFrame using the JScrollbar?

為{幸葍}努か 提交于 2019-12-18 05:50:03
问题 I have a problem. I have a JFrame with some JTextFields, JLabels, Jlists & JButtons now the contents of my frame is more than the screen area so I want to attach a JScrollBar to my JFrame but my srollbar does not work. So, can anyone please guide me on how I can scroll my JFrame using the JScrollbar? 回答1: Put all the components in one panel (instead of in the JFrame) Add this panel to a JScrollPane Add the JScrollPane to your frame. I should be something like: JPanel container = new JPanel();

Java JPanel tiled background image

。_饼干妹妹 提交于 2019-12-18 05:06:19
问题 I currently have the code for creating a JOptionPane that tiles an image to the background no matter the size I set it to :) package test; import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; public class TiledImage extends JPanel { BufferedImage tileImage; public TiledImage(BufferedImage image) { tileImage = image; } protected void paintComponent(Graphics g) { int width = getWidth(); int height = getHeight(); for (int x

Java getting download progress

此生再无相见时 提交于 2019-12-18 04:53:01
问题 I am writing a Java application (Using NetBeans as an IDE and a jFrame form), and one part of it downloads a file. How can I update a progress bar with the current progress of the download, or at least get the total amount of currently downloaded bytes in another thread? Below is a part of my code: Runnable updatethread = new Runnable() { public void run() { try { java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL("server/package.zip").openStream()); java.io

hiding title bar of JInternalFrame? -java

妖精的绣舞 提交于 2019-12-18 04:09:35
问题 I found some code online, I edited it a bit. I want to hide title bar of a JInternalFrame. JInternalFrame frame = new JInternalFrame(); // Get the title bar and set it to null setRootPaneCheckingEnabled(false); javax.swing.plaf.InternalFrameUI ifu= frame.getUI(); ((javax.swing.plaf.basic.BasicInternalFrameUI)ifu).setNorthPane(null); frame.setLocation(i*50+10, i*50+10); frame.setSize(200, 150); //frame.setBackground(Color.white); frame.setVisible(true); desktop.add(frame); The problem is that

JFrame resizable height ONLY

梦想的初衷 提交于 2019-12-18 02:57:06
问题 JFrame.setResizable(true) lets the user resize both the width and height of a window. Does a method exist which allows the user to ONLY resize the height? Thanks. Edit: The solutions below do NOT seem to work. On a 360x600 JFrame, setResizable(true); pack(); setMaximizedBounds(new java.awt.Rectangle(0, 0, 360, 1200)); setMaximumSize(new java.awt.Dimension(360, 1200)); setMinimumSize(new java.awt.Dimension(360, 600)); setPreferredSize(new java.awt.Dimension(360, 600)); setVisible(true); Still

Java Swing — Key Input with JPanel added to JOptionpane

江枫思渺然 提交于 2019-12-17 21:22:21
问题 When I run the code, the added Example1 class to the JOptionPane (in Frame) should get keyInput and then change the y value of the player instance (in example1), but it doesn't work. Also, how would I be able to rotate the ship on its axis and then move in the direction its facing? Currently it moves in the direction its rotated towards, but it rotates on what seems the coordinates 0,0. Frame import javax.swing.*; import java.awt.*; /** * Created by griffin on 12/7/2015. */ public class Frame