jframe

Java - how do I prevent WindowClosing from actually closing the window

谁说我不能喝 提交于 2019-11-27 20:21:38
I seem to have the reverse problem to most people. I have the following pretty standard code to see if the user wants to do some saves before closing the window: frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { boolean close = true; // check some files, asking if the user wants to save // YES and NO handle OK, but if the user hits Cancel on any file, // I want to abort the close process // So if any of them hit Cancel, I set "close" to false if (close) { frame.dispose(); System.exit(0)

How can I refresh or reload the JFrame? [closed]

坚强是说给别人听的谎言 提交于 2019-11-27 20:12:25
I am doing project using Java and in that I need to reload whole JFrame after clicking particular button on that JFrame . How to do this? Alim Ul Gias Try SwingUtilities.updateComponentTreeUI(frame); If it still doesn't work then after completing the above step try frame.invalidate(); frame.validate(); frame.repaint(); just use frame.setVisible(false); frame.setVisible(true); I've had this problem with JLabels with images, and this solved it Here's a short code that might help. <yourJFrameName> main = new <yourJFrameName>(); main.setVisible(true); this.dispose(); where... main.setVisible(true)

Java rounded corners on JFrame?

╄→гoц情女王★ 提交于 2019-11-27 18:41:25
问题 I have a login JFrame for my application and i would like to make the corners of the frame rounded by a few pixles. Id like to do this without using transparency on the JFrame and having to use a background image inside a JPanel - is this possible? 回答1: It's possible with undecorated frame, consider the following example: JFrame frame = new JFrame(); frame.setUndecorated(true); frame.setShape(new RoundRectangle2D.Double(10, 10, 100, 100, 50, 50)); frame.setSize(300, 200); frame.setVisible

How to add support for resizing when using an undecorated JFrame?

淺唱寂寞╮ 提交于 2019-11-27 18:06:41
问题 I would like to customize my titlebar, minimize-, maximize- and the close-button. So I used setUndecorated(true); on my JFrame, but I still want to be able to resize the window. What is the best way to implement that? I have a border on the RootPane, and I could use MouseListeners on the Border or the RootPane. Any recommendations? import java.awt.Color; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.border

Transparent JPanel

岁酱吖の 提交于 2019-11-27 16:26:49
问题 I want to create a semi-transparent JPanel. I've done it by simply using RGBA value of color constructor but problem is when i m using event handling is not woking properly. My requirement is a semi transparent Jpanel when mouse enters it border of this panel became visible and if mouse exit the border shoud not visible. I have done this by following code but problem is its not working properly for transparent backgroud (RGBA) but it working fine for RGB color. import javax.swing.*; import

JFrame not presenting any Components

独自空忆成欢 提交于 2019-11-27 16:20:49
I am using the following code to create a very simple JFrame , but for some reason it doesn't show any components, just a blank frame. Why is this happening? I created frames a bunch of times and I just can't figure out what is wrong. The code is: Main(){ JFrame frame = new JFrame("Colorizer | By: NonameSL"); frame.setSize(400,200); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); frame.setContentPane(panel); textField=new JTextField("Enter your name!"); textField.setBounds(0,0,40,200); textField

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

醉酒当歌 提交于 2019-11-27 16:14:10
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, which is simple enough. Thanks in advance. Don't display the window as a JFrame but rather display it as a

Why do we need to extend JFrame in a swing application?

不羁的心 提交于 2019-11-27 16:10:58
Why do we need to extend the JFrame class when building a Swing application. As far as I know extends is used for inheriting the base class. None of the functions of the JFrame class are used in the following program but still it is extended. I know I am missing out on some information. Is it like some of the functions of JFrame class are running in the background. 1) Code import java.awt.Container; import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JFrame; import javax.swing.JTextField; import javax.swing.JPasswordField;

BufferStrategy vs DIY Double Buffering in JFrame

允我心安 提交于 2019-11-27 15:57:57
Until now, I've done double buffering by creating and Image, drawing what I wanted to that Image using its associated Graphics object then draw that Image to the screen using the paint method's Graphics object. Recently, I learned about the BufferStrategy class and its uses. I was wondering what are the pros and cons of the two methods. EDIT: I dont't think I made my question very clear. I wanted to know the pros/cons of both the DIY method and the BufferStrategy and when, if ever, I should use one or the other. I've always had good results using the default BufferStrategy by being careful to

How to switch JPanels in a JFrame from within the panel?

若如初见. 提交于 2019-11-27 15:54:18
So, I'm trying to make a basic functional menu for a simple game. I tried to do this by creating 2 JPanels, one for the actual game, and another for my menu. What I'm trying to do is have a button on my Menu panel that when pressed, switches the JPanel being displayed in the parent JFrame from that of the menu to that of the actual game. Here is my code: class Menu extends JPanel { public Menu() { JButton startButton = new JButton("Start!"); startButton.addActionListener(new Listener()); add(startButton); } private class Listener implements ActionListener { public void actionPerformed