jframe

JTable not showing up on JFrame (Java)

拟墨画扇 提交于 2019-11-26 11:54:54
I'm having a problem with a JFrame not showing a JTable that is added to it. I've tried getContentPane().add(..) , I've switched to just add to keep the code a little shorter. Any help is more than appreciated! package com.embah.Accgui; import java.awt.*; import javax.swing.*; public class accCreator extends JFrame { private String[] columnNames = {"Username", "Password", "Members", "World"}; private Object[][] data = {{"b", "b", "b", "b"}, { "e", "e", "e", "e"}}; private JTable tbl_Accounts; private JScrollPane scrollPane; private JLabel lbl_Account = new JLabel(); private JLabel lbl_Username

How to set JFrame to appear centered, regardless of monitor resolution?

有些话、适合烂在心里 提交于 2019-11-26 11:50:19
问题 While working with Java, I find it hard to position my main window in the center of the screen when I start the application. Is there any way I can do that? It doesn\'t have to be vertically centered, horizontal alignment is the more important goal for me. But vertical alignment is also welcome. 回答1: I always did it in this way: Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2); where this is

Is there any way I can rotate this 90 degrees?

孤街醉人 提交于 2019-11-26 11:40:33
问题 This is my current code: package Calendar; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.Timer; public class Clock extends JLabel { private String pattern; private Timer timer; public Clock(String pattern){ this.pattern = pattern; createTimer(); timer.start(); } public Clock(){ pattern = \"hh:mm:ss a\";

Java Swing Blank JFrame coming up?

蓝咒 提交于 2019-11-26 11:39:43
问题 I\'m new to swing, and was wondering why sometimes my application comes up as blank, and sometimes it displays the components. It seems to be sporadic. There are no exceptions thrown or anything like that. It just frequently comes up as a blank JFrame. At times when I close the application and run it again, it shows the components correctly, but it mainly comes up as blank. Am I doing something wrong in the code? I\'m using the Eclipse IDE, if it matters. Here\'s the code: import java.applet

How to add an image to a JFrame title bar?

跟風遠走 提交于 2019-11-26 11:39:26
问题 I want to add an image (small icon) to the javax.swing.JFrame title bar. How can I do it? 回答1: Since JPanel doesn't have a title bar, I'm assuming that you're referring to JFrame . That being said, use setIconImage(...). Here is an example of using setIconImages() . import java.awt.Image; import javax.swing.*; import javax.imageio.ImageIO; import java.net.URL; import java.util.*; class FrameIcons { public static void main(String[] args) throws Exception { URL url16 = new URL("http://i.stack

Java Swing adding Action Listener for EXIT_ON_CLOSE

让人想犯罪 __ 提交于 2019-11-26 11:26:08
问题 I have a simple GUI: public class MyGUI extends JFrame{ public MyGUI(){ run(); } void run(){ setSize(100, 100); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// maybe an action listener here } } I would like to print out this message: System.out.println(\"Closed\"); When the GUI is closed (when the X is pressed). How can I do that? 回答1: Try this. addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.out.println("Closed"); e

How do I draw an image to a JPanel or JFrame?

断了今生、忘了曾经 提交于 2019-11-26 11:25:48
问题 How do I draw an Image to a JPanel or JFrame, I have already read oracle\'s tutorial on this but I can\'t seem to get it right. I need the image \" BeachRoad.png \" to be displayed on a specific set of coordinates. Here is what I have so far. public class Level1 extends JFrame implements ActionListener { static JLayeredPane EverythingButPlayer; static Level1 l1; public Level1() { EverythingButPlayer = new JLayeredPane(); BufferedImage img = null; try { img = ImageIO.read(new File(\"BeachRoad

Center JDialog over parent

做~自己de王妃 提交于 2019-11-26 11:21:22
问题 I have a Java swing application with a button that produces a popup window when a certain action is performed. I\'d like to align the center point of the popup window with the center point of the parent window when it is rendered. How can I calculate the x,y coordinates to plug into setLocation() for the popup window? Just to clarify. I do not want the behavior of setLocationRelativeTo() because that sets the top-left pixel of the popup over the center pixel of the parent frame. I want to set

How can I scroll more than one object at the same time?

梦想与她 提交于 2019-11-26 10:48:27
New question was asked after this one, found here . I'm new to Java, but I am working on a recreation of "Flappy Bird" to learn more about java and the way that graphics are displayed. Any solutions or suggestions to any of my questions is greatly appreciated. Thanks! Right now, my program makes a random pipe and scrolls it, but I don't need it to keep scrolling when x1-3 = -83 ( this is when the pipe will be off of the screen completely and is no longer needed ). Questions How can I make my Game.class scroll more than one instance of Pipes.class while adding a preset distance between them? I

Sizes of frame icons used in Swing

不问归期 提交于 2019-11-26 10:34:21
We can use a list to initialise the window icons using Window.setIconImages(List<? extends Image>) . What are the different sizes of icons typically used for in a JFrame ? Code This code turns 64 different sized images (from 16x16, incrementing by 2) into icons for the list. import java.awt.*; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Vector; import javax.swing.*; import javax.swing.border.EmptyBorder; public class FrameIconList { public static BufferedImage getImage(int size, Color color) { BufferedImage i = new BufferedImage( size, size, BufferedImage