jframe

Java Swing JFrame Layout

心不动则不痛 提交于 2019-12-17 18:55:01
问题 I just wrote a simple code where I want a textfield and a button to appear on the main frame, but after running all I see is the textfield. If I write the code of the button after the textfield then only the button is displayed. Any idea why? JFrame mainframe=new JFrame(); mainframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainframe.setBounds(0,0,200,200); JButton jb=new JButton(); jb.setText("Leech"); mainframe.add(jb); JTextField link=new JTextField(50); mainframe.add(link);

Java Label Timer and Saving

孤者浪人 提交于 2019-12-17 17:23:24
问题 Let me explain what I am trying to do. I have two classes extending JFrame , the StartJFrame and TestingJFrame . In the main method, I start up a StartJFrame . It has a single button, start. When that is pressed, I have it set up to hide that frame and start up the TestingJFrame . Right now I don't have anything in the T estingJFrame . In that screen, I want to have a label in the bottom right corner that is a timer, starting on 45 seconds and counting down to 0. I also need to have some code

Dispose JFrame from another class

 ̄綄美尐妖づ 提交于 2019-12-17 17:15:33
问题 How can I dispose JFrame from another class? My code is listed below. I use Netbeans generate form for generate window. And I want dispose using another class(name is needDispose). public class needDispose { /** *Call for dispose frame */ public static void disposeMyFrame(){ myEasyFrame.getMainFrame.dispose(); // DOESNT WORK } } NETBEANS GENERATE (important method is getMainFrame() ) import javax.swing.JFrame; public class myEasyFrame extends javax.swing.JFrame { /* * Get frame */ public

Communication between two different JFrames?

限于喜欢 提交于 2019-12-17 16:31:06
问题 Hello as maybe you have heard about GIMP or something like that which uses different frames As a complete gui so I was wondering how to do such frames communications when both(maybe multiple) frames are loaded in memory and are visible. I have gone through some articles but they were not so satisfactory, if anyone have a good example or tutorial then please share. Regards Alok sharma 回答1: Basically, it's just a matter of having a reference to frame A in frame B, and a reference to frame B in

How do you return a value from a java swing window closes from a button?

元气小坏坏 提交于 2019-12-17 14:51:04
问题 Basically, I have somewhere in my main code where this line of code is called editwindow clubeditwindow = new editwindow(1,"Club Edit"); This line opens a new JFrame that can basically edit a bunch of information from the main class. I have 2 buttons called save and cancel. When save is clicked, I want to take the values from the textfields and then put it into a new object and return that to the main class, and close the window. When cancel is clicked, I want it to just not do anything,

Java/Swing: Obtain Window/JFrame from inside a JPanel

岁酱吖の 提交于 2019-12-17 10:25:44
问题 How can I get the JFrame in which a JPanel is living? My current solution is to ask the panel for it's parent (and so on) until I find a Window: Container parent = this; // this is a JPanel do { parent = parent.getParent(); } while (!(parent instanceof Window) && parent != null); if (parent != null) { // found a parent Window } Is there a more elegant way, a method in the Standard Library may be? 回答1: You could use SwingUtilities.getWindowAncestor(...) method that will return a Window that

how to create own file with icon that inherit from JFrame icon, that I set it, in java and my own file use FileOutputStream and ObjectOutputStream

若如初见. 提交于 2019-12-17 10:02:55
问题 I want to create my own file with icon that inherit from JFrame icon, that I set it, in java and my own file use FileOutputStream and ObjectOutputStream try { ObjectOutputStream oos; //I create own file with own extension in drive D: FileOutputStream fos = new FileOutputStream("D:/myFile.ckl"); oos = new ObjectOutputStream(fos); //Write Document in JTextPane to File oos.writeObject(jTextPane.getStyledDocument()); oos.close(); fos.close(); } catch (Exception exp) { JOptionPane

Java Container remove method not working correctly

血红的双手。 提交于 2019-12-17 07:53:44
问题 i hava added 1.TextArea 2.TextField then i start adding JButton successively on container...,now by using JRadioButton i want to remove JButton from container using this code i=0; k=0; while(!birdButton[i].isSelected()){ i++; } System.out.println(i); k=i+2; list.removeElementAt(i); listName.removeElementAt(i); System.out.println(k); c.getContentPane().remove(k); but when i select the 1st radiobutton 1st JButton should be deleted because of k=i+2; instead of deleting this one it deletes the

Clear components of JFrame and add new components

可紊 提交于 2019-12-17 07:41:29
问题 I have a JFrame , which have some options. When OK button is pressed i want the same JFrame to clear the contents and add new contents. I have tried it but the problem is new JFrame is popped out. What am I doing wrong? import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*;

How can I customize the title bar on JFrame?

风流意气都作罢 提交于 2019-12-17 06:45:31
问题 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: 回答1: You can see an example