jframe

How to correctly implement MVC in Java with Swing?

这一生的挚爱 提交于 2019-11-30 12:04:37
问题 If you would like more details please let me know, or refer to the last lines of this question. I've already read a lot and I feel I'm turning something simple into something complicated and I still get stuck here and there, so maybe you can help me in those very specific points. I'm using Netbeans IDE 7 and JDK 7, and no frameworks. The first Window is a JFrame and all other windows are JDialogs with modal=true. Questions: How do I correctly implement the MVC pattern with swing? From the

Adding JPanel from another class to JPanel in JFrame

空扰寡人 提交于 2019-11-30 09:05:43
I can't get my JFrame from main class to display JPanel from another class. Everything compiles without errors. JFrameTest.java: package jframetest; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class JFrameTest extends JFrame { public JFrameTest() { FlowLayout mainLayout = new FlowLayout(); setSize(320, 480); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(mainLayout); JPanel panelMain = new JPanel(mainLayout); JButton testButton = new JButton("Test12"); panelMain.add(testButton); JPanelOne

refresh JFrame after adding new Components

你说的曾经没有我的故事 提交于 2019-11-30 08:06:58
I want to add some new Components to my JFrame during runtime when a button is pressed. This works so far, but i have to resize the window manually to see the new components. Is there any Action I can fire or a method to call to refresh the window? Any help appreciated. Thanks in advance. crusam You have to revalidate(); the frame. If that doesn't work you also have to call repaint(); Call revalidate(); repaint(); revalidate tells the layout manager to reset based on the new component list. This will also trigger a call to repaint. repaint is used to tell a component to repaint itself. in java

Adding components into JPanel inside a JFrame

淺唱寂寞╮ 提交于 2019-11-30 07:49:35
问题 Since im a beginner and i don't want to get involved with the layout managers, i was simply adding a JPanel into my main JFrame and giving spesific location to each component in the panel. But somehow the output appears way too wrong.. frame = new JFrame(email + " (Offline)"); frame.setSize(400, 400); frame.setLocation(0, 0); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.setLayout(new FlowLayout()); frame.addWindowListener(new WindowAdapter() { public void windowClosing

Pass values entered in one JFrame's text field as an input parameter in other JFrame

十年热恋 提交于 2019-11-30 07:45:19
问题 How to pass values entered in one JFrame's text field as an input parameter in other JFrame? Entered user name and password in first JFrame through JTextFields .. String usr = jTextField2.getText(); String pass = jTextField3.getText(); Same username and password should be given as input in forth frame each frame is redirected to other on button click 回答1: Suppose you have many frames, you have to create instance variables for that purpose. If you don't know what an instance variable see this

How can I display a BufferedImage in a JFrame?

拜拜、爱过 提交于 2019-11-30 07:24:48
问题 I want to display variations of the same image in the same JFrame, for example display an image in JFrame, then replace it with gray scale of the same image. 回答1: You will have to repaint the JFrame whenever you update the image. Here is what a simple google on the topic brings up: (I use those tutorials for all my Java coding) Java Tutorial: Drawing an Image 回答2: To build on camickr's solution (for the lazy like me who want quick code to copy/paste) here's a code illustration: JFrame frame =

Building a GUI for a Sudoku Solver (Complete with ASCII Example)

两盒软妹~` 提交于 2019-11-30 06:42:10
. OVERVIEW, SAMPLE Hello everyone, I have created a basic Sudoku solver that can solve most problems fairly quickly. I still have a lot of work ahead of me to make it solve even the hardest problems, but I'd like to try to implement a basic JFrame GUI first. I have worked with internet applets in the past, but never before with JFrames. I want to create something similar to the image below (for starters): ------------------------------------------------------------------------------------------------- ! Sudoku Solver 1.0 - [] X ! ----------------------------------------------------------------

How to layout multiple panels on a jFrame? (java)

若如初见. 提交于 2019-11-30 05:08:05
I am in the process of making my own java socket game. My game is painting alright to the full screen (where it says "paint graphics here", but im painting to the whole jframe at the moment). I want to add a textbox with a scroll bar for displaying only text, not taking any input and another textbox to take text inputs from the user and then a button to send the text, for chat purposes. But onto my question, how do I even start to lay this out? I understand I need a layout, but can someone help me on this? Here is my code at the moment (this code only sets up painting to the whole screen at

When a JasperViewer appear and I close it, the main frame/parent also closed [duplicate]

我们两清 提交于 2019-11-30 04:55:17
问题 This question already has an answer here : How to prevent parent frame closed when closing child frame (Java + iReport)? (1 answer) Closed last year . When a JasperViewer appear and I close it, the main frame / parent also closed. How to prevent this? This is my code.. private void cmdprintidMouseClicked(java.awt.event.MouseEvent evt) { // TODO add your handling code here: try { JasperDesign jasperDesign = JRXmlLoader.load("report12.jrxml"); String sql = "select * from db1 where Company LIKE

JFrame: How to disable window resizing?

橙三吉。 提交于 2019-11-30 02:44:38
I am creating a JFrame and I call the method setSize(500, 500) . Now the desired behaviour is that JFrame should not be resized by user in any condition. Either by maximizing or by dragging the borders. It should be 500x500. How can I do it? I have also attached the code in case you can guide me better. package com.techpapa; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class MainWindow extends JFrame{ private JTextField write; private JRadioButton rb1, rb2, rb3; private ButtonGroup bg; private ActionListener al = new ActionListener(){ public void actionPerformed