jframe

Java: How to cancel application exit

强颜欢笑 提交于 2019-12-01 17:36:59
On one of my programs, I want a Dialog to appear when the user attempts to exit the application. The user must then choose to save some state of the program, not to save or to cancel the exit operation. I wrote this in an attempt to find a solution first and ony then implement it: import javax.swing.*; import java.awt.Dimension; import java.awt.event.*; class WL implements WindowListener { private boolean statussaved; private JFrame tframe; WL (JFrame frame) { statussaved = false; tframe = frame; } @Override public void windowActivated (WindowEvent w) { } @Override public void windowClosed

How to make JFrame background and JPanel transparent with only image showing

一世执手 提交于 2019-12-01 17:25:46
Hey I am trying to make a some kind of launcher and the "window" must be transparent because I want the image I am using to be the design of it if you understand what I mean. I tried to do setUndecorated(true); and setBackground(new Color(0, 0, 0, 0)); but it just looked weird. Here is a picture on how it looks: http://prntscr.com/2pqohq Here is my code: import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.GridBagLayout; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java

How to make JFrame background and JPanel transparent with only image showing

妖精的绣舞 提交于 2019-12-01 17:02:29
问题 Hey I am trying to make a some kind of launcher and the "window" must be transparent because I want the image I am using to be the design of it if you understand what I mean. I tried to do setUndecorated(true); and setBackground(new Color(0, 0, 0, 0)); but it just looked weird. Here is a picture on how it looks: http://prntscr.com/2pqohq Here is my code: import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.GridBagLayout; import java.awt.image

I have to resize my JFrame for the contents to show up. How can i fix that?

天涯浪子 提交于 2019-12-01 16:30:02
问题 When I run my gui, I have to resize the window for everything to show up. Does someone know what the problem is? 回答1: Call pack() on your JFrame, after adding all your components and before calling setVisible(true). 回答2: When you create the frame call the setSize() method on the frame to set the initial starting size. 回答3: setVisible(true); after you have added all desired JComponents to your JFrame helped for me. 回答4: don't need to add pack() method. Just add the setSize(int, int) on the end

Java: How to cancel application exit

亡梦爱人 提交于 2019-12-01 16:15:14
问题 On one of my programs, I want a Dialog to appear when the user attempts to exit the application. The user must then choose to save some state of the program, not to save or to cancel the exit operation. I wrote this in an attempt to find a solution first and ony then implement it: import javax.swing.*; import java.awt.Dimension; import java.awt.event.*; class WL implements WindowListener { private boolean statussaved; private JFrame tframe; WL (JFrame frame) { statussaved = false; tframe =

Animation on Transparent-background JFrame Linux

戏子无情 提交于 2019-12-01 15:49:42
I want to create a fully transparent background for a Frame (or JFrame) and have it show a transparent animation. I managed to get it working in Windows 7 x64 but the same code does not run on my Linux (Lubuntu x64 15.04). The code below shows what I'm trying to achieve--just copy & paste it. I just want the little rectangle to move across the screen without leaving a trail. static int a = 0; public static void main(String[] args) { JFrame f = new JFrame(); f.setUndecorated(true); f.setBackground(new Color(0, 0, 0, 0)); f.setVisible(true); f.setSize(512, 512); f.add(new JPanel() { @Override

How to prevent JFrame from closing

本小妞迷上赌 提交于 2019-12-01 15:47:25
问题 I have a Java GUI application from which another java GUI application is invoked using reflection and loading. It works fine the only problem faced is, on closing the JFrame of invoked application the Main GUI application frame also closes. How can I prevent the main application (frame) from closing?? I cannot change the defaultCloseOperation of the invoked application, However a change to the main application can be made. Does it have any thing to do with threads?? This is my applications

JButton expanding to take up entire frame/container

萝らか妹 提交于 2019-12-01 15:47:09
问题 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? 回答1: 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 []

How to set the JFrame as a parent to the JDialog

谁说我不能喝 提交于 2019-12-01 15:20:03
I am having trouble to set the frame as a owner to the dialog. Normally when I extend JDialog class for creating a dialog then I use super(frame) to specify the owner of the dialog such that both of them are not disjoint when you press alt+tab . But when I create a dialog using new like JDialog dialog = new JDialog() then I am unable to specify the frame as owner to the dialog. Following example demonstrates above two approaches. Top Click button opens a dialog which is without extending JDialog . Bottom Click button opens a dialog with extending JDialog . import java.awt.BorderLayout; import

Animation on Transparent-background JFrame Linux

六月ゝ 毕业季﹏ 提交于 2019-12-01 15:00:29
问题 I want to create a fully transparent background for a Frame (or JFrame) and have it show a transparent animation. I managed to get it working in Windows 7 x64 but the same code does not run on my Linux (Lubuntu x64 15.04). The code below shows what I'm trying to achieve--just copy & paste it. I just want the little rectangle to move across the screen without leaving a trail. static int a = 0; public static void main(String[] args) { JFrame f = new JFrame(); f.setUndecorated(true); f