jframe

Working with 2 or more frames

冷暖自知 提交于 2019-11-27 02:27:23
问题 I have about 3 frames in my java swing application. What it the correct way how to handle with these frames? I mean some pattern or something else. Now I have always one class which represent frame and one class for panel which is main in this frame. Now I have defined frames as static variable and when I wanna hide them I call classname.frameName.setVisible(false); is this the correct solution? 回答1: Besides the (excellent) suggestions of a CardLayout or JFrame with multiple JDialog instances

Java JFrame .setSize(x, y) not working?

妖精的绣舞 提交于 2019-11-27 02:26:28
When I execute this bit of code, a tiny window pops up that, and the inside of it is about 116x63, and the entire size including the border of ~140x100. How do I set the inside to be what I need it to? public static void graphics() { JFrame frame = new JFrame(); String title = "test window"; frame.setTitle(title); frame.setSize(gridRow, gridCol); //101 x 101 frame.setResizable(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } MadProgrammer Create a custom component, extending from JPanel , override its getPreferredSize method to return the size of the

SwingWorker in another SwingWorker's done method

China☆狼群 提交于 2019-11-27 02:17:32
First, I need to inform you that I am trying my hardest to learn how to code in Java. Its been a little bit difficult, but, I do believe I have it. I have submitted a couple question in the past in regards to SwingWorkers and the like. Each of which I thought I had it, but come to find out that I still had learning to do. Hopefully this time, is not one of those times. With that said, please let me know of anything you see that isn't to standard, or, could lead to problems in the future. Now for the question! I have constructed a JFrame, of which, loads a couple things before it allows the

FlowLayout on top of GridLayout not working

纵饮孤独 提交于 2019-11-27 02:14:49
I'm trying to create a hangman game and so far it's coming along GREAT, but the layout design just doesn't seem to fall into place! The alphabet is supposed to end up in a FlowLayout order on top of the Hangman picture with the buttons "Restart", "Help" "Add New Word" and "Exit" at the bottom! What am I doing wrong? import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; public class Hangman extends JFrame { int i = 0; static JPanel panel; static JPanel panel2; static JPanel panel3; public Hangman() { JButton[] buttons = new JButton[26]; panel = new JPanel(new

How to add multiple components to a JFrame?

半城伤御伤魂 提交于 2019-11-27 02:14:31
I have a JFrame . I also have a Box class which extends Component . This box class has a paint method which makes a filled rectangle. When I add multiple of these Box components to my JFrame, only the most recently added one is displayed when I call repaint on the JFrame. I took a look at the layout managers, but I am not sure that's what I want. All I want is to be able to make an animation of whole bunch of rectangles wherever I want on the screen. (I also tried creating a panel, adding the panel to the JFrame, and then adding all the Box components to the panel. This did not work either).

All JFrame freeze while do JavaMail

╄→尐↘猪︶ㄣ 提交于 2019-11-27 02:12:29
I develop program of car management system. Then I want to send mail to owner of this company when car coming in and car out. My code can send mail successfully but I notice that while mail send, other JFrame window is freeze (I can't do anything on all JFrame window) until mail send is complete. Is this normally for Javamail or there is a way to make other JFrame still working? In my program, it take about 10 seconds to complete send one mail. When you do heavy task you should run them in another threads rather in the same as gui. If you run in Event Dispatch Thread then the gui is gonna

Get Any/All Active JFrames in Java Application?

只谈情不闲聊 提交于 2019-11-27 02:10:12
问题 Is there a way from within a Java application to list all of the currently open/active (I'm not sure the terminology here) JFrames that are visible on screen? Thanks for your help. 回答1: Frame.getFrames() returns an array of all frames. Alternately as mentioned by @mKorbel, Window.getWindows() will return all windows - since Frame (& JFrame ) extend Window that will provide all frames, and then some. It will be necessary to iterate them to discover which ones are currently visible. 回答2: I

Why are my items not showing up in JFrame?

微笑、不失礼 提交于 2019-11-27 02:03:18
I'm fairly new to JFrame and I want to know why my items are not showing up on the window. I know i dont have a ActionHandler but I just want my textfield's to show up on my window. Here's my code: import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; public class FirstGUI extends JFrame{ public void GUI(){ setTitle("Welcome"); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); setSize(600,600); JLabel title = new JLabel(); title.setText("Apple Inc. Member Login Port");

how to set JFrame background transparent but JPanel or JLabel Background opaque?

柔情痞子 提交于 2019-11-27 01:38:44
As per assignment, we have to create a image viewer just like Picasas one. picture in the middle, translucent black background and changing images with left/right buttons. i can display an image set it to undercoated, set it to translucent frame but along with frame the the picture becomes translucent. what am i doing wrong. Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); JFrame f1 = new JFrame("ShowImage"); f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f1.setSize(dim); f1.setUndecorated(true); f1.setOpacity(0.5f); ShowImage panel = new ShowImage(); panel.setBackground(Color

How can I customize the title bar on JFrame?

拜拜、爱过 提交于 2019-11-27 01:37:58
I would like to have a customized title bar in my Java Swing desktop application. What is the best way to do that? I can use a "Swing-title bar" by using the following code in the constructor for my JFrame: this.setUndecorated(true); this.getRootPane().setWindowDecorationStyle(JRootPane.FRAME); But how do I customize it? Is there any UI delegates that I can override or do I have to implement my own title bar from scratch? I want something like Lawson Smart Office: Kirill You can see an example in Substance look-and-feel ( mirrored source ). Search the code for SubstanceRootPaneUI and