jframe

Best practice for setting JFrame locations

别说谁变了你拦得住时间么 提交于 2019-11-26 02:02:25
I have a (somewhat philosophical) question relatively to Swing, or to GUI programming in general. Are there recognized best practices on where to locate the JFrame instances used in the application? Where should the first and main frame be located? Always at the center ( setLocationRelativeTo(null) )? Where should a child JFrame be located? Relatively to its parent JFrame , at the center of the screen, wherever we want? I have always assumed there were some best practices, kind of a "GUI bible" about this, am I wrong and should I (gasp) arbitrarily decide what to do? Andrew Thompson Here is an

Printing a JFrame and its components

不打扰是莪最后的温柔 提交于 2019-11-26 01:54:26
问题 I have been working in a big program and one of its functionalities should be to print the contents of the main window. I checked the API and found this example: http://docs.oracle.com/javase/tutorial/2d/printing/gui.html it was very helpful, I tried to use that code in my program by placing this inside the actionperformed method of my print button: PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintable(this); boolean ok = job.printDialog(); if (ok) { try { job.print(); } catch

Best practice for setting JFrame locations

こ雲淡風輕ζ 提交于 2019-11-26 01:49:49
问题 I have a (somewhat philosophical) question relatively to Swing, or to GUI programming in general. Are there recognized best practices on where to locate the JFrame instances used in the application? Where should the first and main frame be located? Always at the center ( setLocationRelativeTo(null) )? Where should a child JFrame be located? Relatively to its parent JFrame , at the center of the screen, wherever we want? I have always assumed there were some best practices, kind of a \"GUI

How to set output stream to TextArea

微笑、不失礼 提交于 2019-11-26 01:43:43
问题 I\'m trying to create a GUI Panel for a program and I\'d like everything, that would normally print to my command prompt, to print to a TextArea object. I have the GUI panel formatted for the most part, I can\'t get the text to print to the TextArea though, here\'s my file: package guipanel; import javax.swing.*; import java.awt.*; import java.io.*; /** * * @author Dan */ public class GUIPanel extends JFrame { public GUIPanel() { initComponents(); } private void setOutputStream(boolean

Java Bouncing Ball

不问归期 提交于 2019-11-26 01:21:08
问题 I am trying to write a Java application which draws multiple balls on screen which bounce off of the edges of the frame. I can successfully draw one ball. However when I add the second ball it overwrites the initial ball that I have drawn. The code is: import java.awt.*; import javax.swing.*; import java.util.ArrayList; import java.util.List; public class Ball extends JPanel implements Runnable { List<Ball> balls = new ArrayList<Ball>(); Color color; int diameter; long delay; private int x;

Why does the first panel added to a frame disappear?

∥☆過路亽.° 提交于 2019-11-26 01:09:31
问题 Below is an example of adding two panels to a frame. Only one panel (the 2nd, red panel) appears. Why does the first panel disappear? import java.awt.*; import javax.swing.*; import javax.swing.border.EmptyBorder; public class DisappearingPanelInFrame { DisappearingPanelInFrame() { JFrame f = new JFrame(this.getClass().getSimpleName()); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.add(new ColoredPanel(Color.GREEN)); f.add(new ColoredPanel(Color.RED)); f.pack(); f.setVisible(true); }

JPanel repaint issue

只谈情不闲聊 提交于 2019-11-26 01:09:20
问题 I have a JFrame which contains 2 JPanel subclass and 2 JLabel in BorderLayout. One of the JPanel contains JButtons and the other is used for displaying graphics. The JLabels are in north and south, the button JPanel in the west and the display JPanel in center. The display JPanel requires constant refresh, so i invoke its repaint() method via the action event generated by swing timer. I also override its paintComponent() method to do my drawings. Instead of displaying what i have drawn, the \

Only one component shows up in JFrame

南楼画角 提交于 2019-11-26 00:49:08
问题 As an improvement to my encryption project I decided to make a little GUI. However, when I run the program, only the top element shows up on the screen and it appears to obscure the others, though I have no way of checking. Does anyone know why? Below is my code in its entirety besides e() and d() because those simply encrypt a string and have nothing to do with a GUI. I would also like a way to speed it up as much as possible without editing the encryption, just to make it as great as

Calling one JFrame from another using Timer without any buttons

a 夏天 提交于 2019-11-26 00:49:08
问题 Calling one JFrame from another using Timer without any buttons: time is decreased then open another JFrame without any buttons. Please help. Used in netbeans 回答1: Your question is very unclear, but the use of multiple frames is not recommended. As an alternative, consider a modeless dialog, shown below. The dialog's enclosed JOptionPane listens for a PropertyChangeEvent , while counting down from TIME_OUT using javax.swing.Timer . The JOptionPane button is convenient but not required .

How do I Switch JPanels inside a JFrame

风流意气都作罢 提交于 2019-11-26 00:44:50
问题 Quite green regarding javas component-stuff etc so please excuse me if information given by me isn\'t enough! Considet the code below. Adding menu and menu showing in frame, no problem. I want when gameOn() is called to remove the menu and instead start the game. The code below only makes the Frames surface \"blank\", no gamepanel added. Any thoughts/suggestions on how to fix it? The MenuPanel has a mouselistener. public class GameFrame extends JFrame { private MenuPanel mp; //extends JPanel