jframe

Accessing JComboBox data from separate JForm

房东的猫 提交于 2019-12-01 20:51:49
I've spent a bit of time browsing Stack Overflow and the internet looking for the answer to my question, but I found all the answers hard to understand and I was quite unsure if any of them related to my problem, so I decided I needed help in the right context. I am creating a program that will give a series of solutions based on a particular type of graph inputted. I am sincerely struggling with taking the data from my JComboBox in the first JFrame, and displaying it in the second. I have two classes, GraphEquationSolverGUI and DefineEquation. I am using the Netbeans IDE and

Loading image in Java Code from C drive

為{幸葍}努か 提交于 2019-12-01 20:25:02
i am new to Java . i was just trying to load image as background in JFrame . What i wanted to do is get the image from C Drive(that is not my workspace) so what i did in Board.java : ImageIcon i = new ImageIcon("C:/image.png"); img =i.getImage(); and did try to paint it something like this: public void paint(Graphics g ) { super.paint(g); Graphics2D g2d= (Graphics2D) g; g2d.drawImage(img, 0, 100, null); } And then i am calling in my main class like this public static void main(String[] args) { JFrame frame= new JFrame(" Game") ; frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame

Is it safe to dispose a JFrame from a different thread in Java?

*爱你&永不变心* 提交于 2019-12-01 19:28:06
Is it safe to call the dispose() method of a JFrame from a different thread (not the EDT)? No. It may work or it may cause problems. Just wrap the method in a SwingUtilities.invokeLater(...) and don't worry about it. No, Swing is not thread safe. Use something like Runnable doWorkRunnable = new Runnable() { public void run() { myFrame.dispose(); } }; SwingUtilities.invokeLater(doWorkRunnable); 来源: https://stackoverflow.com/questions/1725661/is-it-safe-to-dispose-a-jframe-from-a-different-thread-in-java

Update content of JPanel on a frame on button click in another frame

五迷三道 提交于 2019-12-01 18:58:43
问题 I have created a frame x1 which has a panel p1. When x1 is loaded, checkboxes are added dynamically to p1. The number of checkboxes added to p1 depend on the number of data values in the database table(t1) that satisfy a particular criteria. There is a button b1 on frame x1. When b1 is clicked,it displays another frame x2 in which data values of the database table t1 can be modified. A button 'update' in x2,updates t1 to reflect the changes made to its data values. After modification,when x2

Update content of JPanel on a frame on button click in another frame

。_饼干妹妹 提交于 2019-12-01 18:46:40
I have created a frame x1 which has a panel p1. When x1 is loaded, checkboxes are added dynamically to p1. The number of checkboxes added to p1 depend on the number of data values in the database table(t1) that satisfy a particular criteria. There is a button b1 on frame x1. When b1 is clicked,it displays another frame x2 in which data values of the database table t1 can be modified. A button 'update' in x2,updates t1 to reflect the changes made to its data values. After modification,when x2 is closed I want the panel p1 in frame x1 to be updated automatically to reflect the changes made to

JFrames and JDialogs sometimes open up behind their parent windows but have focus

一世执手 提交于 2019-12-01 18:14:30
问题 We are developing a rather big Java enterprise application with a traditional Swing client. Every now and then, we facing the problem that random JDialogs and JFrames open up and getting the focus, but are hidden behind their parent windows. Unfortunately, this phenomenon is not reproducible and happens on occasion. So far it was recognized on machines having Win7 and WinXP installed. Since all developers running Windows operating systems, that does not necessarily mean that this problem is

Using paintComponent() to draw rectangle in JFrame

怎甘沉沦 提交于 2019-12-01 18:13:14
问题 I'm trying to create a program that draws shapes (a rectangle on the example below) using JPanel's paintComponent(), but I can't get it to work and can't spot what is wrong. The code is as follows: import javax.swing.*; import java.awt.*; public class RandomRec{ JFrame frame; public void go(){ frame = new JFrame(); frame.setSize(500,500); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); DrawPanel panel = new DrawPanel(); } public static void main (String[] args){

Java: Safe Animations with Swing

情到浓时终转凉″ 提交于 2019-12-01 17:46:30
问题 I am creating a program that uses JFrame, JPanel, JLabel and all other sorts of swing components. What I want to do is create a 2D animation on a separate JPanel that is dedicated to this animation. So I will be overriding the paintComponent (Graphics g) method. I have experience making animations with for loops + Threads, but I am hearing that threads are not safe with swing. Due to this, is it safe for me to make an animation with the use of the Runnable interface? If not what shall I use

How to update JFrame Label within a Thread? - Java

▼魔方 西西 提交于 2019-12-01 17:43:52
I have tried a lot, but can't seem to get it to work. I was told to use EDT with the following example. SwingUtilities.invokeLater(new Runnable() { public void run() { // Modify the GUI here } }); I have read on this topic a lot and still don't understand. I get what a thread is, but the .invokeLater still makes no sense to me. Honestly if you can explain in detail this it would be a big help! Goal of Program: To get the randomly generated key that is constantly created every second to update itself afterward in the GUI. John Vint So there is an EDT (Event Dispatch Thread). All actions that

JButton expanding to take up entire frame/container

ぐ巨炮叔叔 提交于 2019-12-01 17:38:51
Hey everyone. I'm trying to make a swing GUI with a button and a label on it. im using a border layout and the label ( in the north field ) shows up fine, but the button takes up the rest of the frame (it's in the center field). any idea how to fix this? You have to add the button to another panel, and then add that panel to the frame. It turns out the BorderLayout expands what ever component is in the middle Your code should look like this now: Before public static void main( String [] args ) { JLabel label = new JLabel("Some info"); JButton button = new JButton("Ok"); JFrame frame = ...