jframe

Paint in JFrame not working (Java)

為{幸葍}努か 提交于 2020-01-14 10:41:40
问题 So in class we are making a Java program. We are trying to use the paint(Graphics g) function in the JFrame. We have tried it in the past (weeks ago) and it used to work. But now it doesnt (or we made a mistake somewhere). We have also tried to use paintComponent(Graphics g) but nothing seems to work. Here is our code: public class MainAc { public static void main(String[] args) { JFrame frame = new JFrame("Class Paint"); JButton button = new JButton("Click for more"); frame.setSize(800, 600)

Why won't my JFrame respond to mouse and window changes?

我与影子孤独终老i 提交于 2020-01-14 06:36:47
问题 Here is my code: import java.awt.event.*; import java.awt.*; import javax.swing.*; public class wind extends JFrame implements ComponentListener, MouseListener { JButton button; JLabel label; public wind() { // initialise instance variables setTitle("My First Window!"); setSize(400, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); JPanel content = new JPanel(); content.setLayout(new FlowLayout()); content.addComponentListener(this); content.addMouseListener(this); label

JFrame and why stay running

落爺英雄遲暮 提交于 2020-01-14 01:10:45
问题 Why if I create a JFrame then the program still runs until (i.e) I close it with the small "exit button" of the window? I looked for this answer and I failed. The only thing I guessed is that when I do new JFrame() it's like an special new , that keeps a reference of the object in the EDT, so it will always be referenced (even if was an anonymous "new") and it's not going to be deleted by the garbage collector. Then as soon as the event of windows close is triggered, the object is

JFrame and why stay running

偶尔善良 提交于 2020-01-14 01:10:08
问题 Why if I create a JFrame then the program still runs until (i.e) I close it with the small "exit button" of the window? I looked for this answer and I failed. The only thing I guessed is that when I do new JFrame() it's like an special new , that keeps a reference of the object in the EDT, so it will always be referenced (even if was an anonymous "new") and it's not going to be deleted by the garbage collector. Then as soon as the event of windows close is triggered, the object is

How to make a blurry JFrame/JDialog in Java using Swing and JLayer<>?

帅比萌擦擦* 提交于 2020-01-13 10:11:32
问题 I am trying to blur my JFrames. The idea is to blur all components/controls within a JFrame using JLayer/LayerUI. Here's what I have done so far: This is the LayerUI class that makes the blur effect: import java.awt.Component; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.awt.image.BufferedImageOp; import java.awt.image.ConvolveOp; import java.awt.image.Kernel; import javax.swing.JComponent; import javax.swing.plaf.LayerUI; public class

Why isn't JMenu always on top?

守給你的承諾、 提交于 2020-01-13 06:44:05
问题 The JMenu behaves normally until a JButton is used to update a JTable on the JFrame. Then the JMenu is mostly hidden by a JPanel (see images below). Shouldn't the JMenu always be on top when it is selected? Why has it been pushed to the back? The code that updates the table on jButtonAddActionPerformed is. public class MyClass extends javax.swing.JFrame { private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) { DefaultTableModel model = (DefaultTableModel) jTable.getModel();

Java: single frame vs multiple frames

我的梦境 提交于 2020-01-13 04:18:29
问题 Think about the classic installation process, where you have a "next" button and when you click it the content of the window changes. To represent this situation I thought of two possible solutions: -when "next" is clicked destroy the current JFrame and create a new JFrame, maybe passing to his constructor useful information (e.g. actual window size, content inserted by the user in the current frame, ...) -when "next" is clicked remove all the components from the current JFrame and add new

Set the same font for all component Java

感情迁移 提交于 2020-01-12 18:45:14
问题 I want to set a specific font for all component in a JPanel but I prefer that the question is still more general and not limited to the JPanel. How can I set the font to a list of component in a container (JFrame or JPanel)? 回答1: Here is a simple method that allows you to specify Font to the whole components tree under any Container (or just a simple Component, doesn't matter): public static void changeFont ( Component component, Font font ) { component.setFont ( font ); if ( component

confirmation before press YES to exit program in Java

社会主义新天地 提交于 2020-01-12 06:23:52
问题 private void windowClosing(java.awt.event.WindowEvent evt) { int confirmed = JOptionPane.showConfirmDialog(null, "Exit Program?","EXIT",JOptionPane.YES_NO_OPTION); if(confirmed == JOptionPane.YES_OPTION) { dispose(); } } I want to close program by pressing Close Window Button with confirmation...But when I choose "No" to back to my Jframe, it still helps me to exit the program??? 回答1: From what i understand you want something like this addWindowListener(new WindowAdapter() { public void

Disable Background drawing in JFrame in order to properly display Aero (DWM) effects

狂风中的少年 提交于 2020-01-12 03:18:09
问题 I'm having problems using the DWM functionality of Windows Vista/7 on Java windows. I want to make the background of my frame use the Aero style. The Windows API to do so is provide by the function DwmExtendFrameIntoClientArea in the dwmapi library. I've managed to call the procedure properly via JNA, and it does what it is supposed to do (You can see that for example when resizing the frame, before the next repaint you see the proper aero effects in the area not yet painted, see the attached