jframe

Modifying a JFrame from within a Listener [duplicate]

狂风中的少年 提交于 2019-12-07 06:04:29
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How to call setUndecorated() after a frame is made visible? How should I make a JFrame be undecorated when unfocused and decorated when focused? Here's my code: import java.awt.event.*; import javax.swing.*; public class Test extends JFrame { public Test() { setSize(100, 50); addWindowFocusListener(new WindowAdapter() { public void windowGainedFocus(WindowEvent e) { setUndecorated(false); System.out.println("Hi!

How to attach opengl display to a JFrame and dispose of it properly?

不想你离开。 提交于 2019-12-07 04:48:23
问题 How can i attach the OpenGl display to a JFrame and so that when i close the JFrame is destroys the display? Here is my code so far: package test.core; import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color; import java.awt.Component; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JButton; import javax.swing.JFrame; import

Creating a Java Swing JFrame with a circular shape?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-07 04:15:50
问题 How to make a circular JFrame if possible? 回答1: Oracle has a nice tutorial on exactly this topic: https://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html Shaped Windows The other feature introduced in release 6u10 is the window shaping effect. Using shaping you can set any shape to an undecorated window. When the effect is applied, the desired area of a window becomes transparent. Thus, the combination of transparent and non-transparent pixels form the shape of a given

How can I set the insets of a JFrame?

我只是一个虾纸丫 提交于 2019-12-06 21:19:18
问题 Is there a way to set the insets of a JFrame ? I tried frame.getContentPane().getInsets().set(10, 10, 10, 10); and frame.getInsets().set(10, 10, 10, 10); but none of them seem to work. 回答1: JPanel contentPanel = new JPanel(); Border padding = BorderFactory.createEmptyBorder(10, 10, 10, 10); contentPanel.setBorder(padding); yourFrame.setContentPane(contentPanel); So basically, contentPanel is the main container of your frame. 回答2: Overriding the Insets of JFrame would not be the soultion to

Java get JPanel Components

懵懂的女人 提交于 2019-12-06 18:00:48
问题 I have a JPanel full of JTextFields... for (int i=0; i<maxPoints; i++) { JTextField textField = new JTextField(); points.add(textField); } How do I later get the JTextFields in that JPanel? Like if I want their values with TextField.getText(); Thanks 回答1: Well bear in mind they didn't get there by them selves ( I think a read some questions about dynamically creating these panels at runtime ) In the answers posted there, someone said you should kept reference to those textfields in an array.

Adding text to a label from another class - Simple Logic Issue

前提是你 提交于 2019-12-06 16:35:30
I have a label and a button in a class called FrameTest , when i press the button, a method named buttonpressed get's executed from the class Test . In this buttonpressed method i will set a text to the label found in the FrameTest class. The problem i have is that, the text for the label is not getting set. The reason is that i am creating a separate object to call the buttonpressed method; public void actionPerformed(ActionEvent arg0) { Test t = new Test(); t.buttonpress(); } and i am creating a separate object in the main method of the Test class to create the UI. public static void main

Why aren't my coordinates matching my JFrame size?

纵然是瞬间 提交于 2019-12-06 16:15:33
问题 I want to do some drawing in a JPanel but the enclosing JFrame size doesn't seem to match where I've asked the coordinates to be drawn. In my example code, the JFrame size is set to (700, 700) and the last point is drawn at (600, 600). I would expect this point to be drawn 100 pixels away from the right and bottom edges but it isn't (please see screenshot). Here's the code I'm using: import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class Scratch extends

Java, How to refresh JTable in one frame from another frame

橙三吉。 提交于 2019-12-06 15:45:53
So I have a MainFrame class which has a JTable in it, listing all Products stored in DB. The JButton with the help of listeners will open AddProduct (another class, and another window/frame) in which I can add product in the DB. Unfortunately, I'm not exactly sure how can I update/revalidate JTable in MainFrame once AddProduct adds new product and autocloses. Could some please give me some idea as how can I easily resolve this? Since program is rather large, here are relevant parts of it: From MainFrame.java public JPanel tabProducts() { JPanel panel = new JPanel(new MigLayout("","20 [grow,

How to layout? (JFrame, JPanel, etc.)

☆樱花仙子☆ 提交于 2019-12-06 15:31:10
I'm very new to Java Swing and Java overall (my class just got finished on Scanner and basics). I was taught only Swing basics which is "What is a JFrame..etc" and I'm stuck on how to layout or position things. On the image is the layout I desired and could anyone help and teach me how to code it? JFrame with, 5 JPanel components?(4 columns and the order form below) Additionally, when clicking the "CONFIRM" button, I would want a new window to popup. How would I be able to link multiple windows? A common strategy to solve complex computing tasks, is to break them into small, well defined

JFrame.setExtendedState doesn't actually maximise

心不动则不痛 提交于 2019-12-06 15:28:58
public static void main(String args[]){ JFrame frame = new JFrame(); frame.setExtendedState(JFrame.MAXIMISED_BOTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } I've used this code to maximise a JFrame, but instead of actually maximising the frame, it just sets the window size to that of the screen, without actually changing the state, so clicking the maximize button doesn't actually downscale it again. Am I using the wrong command or something? Jesus Flores You have an error in frame.setExtendedState(JFrame.MAXIMISED_BOTH); You should write frame