jframe

call paintcomponent for a jpanel in jframe

陌路散爱 提交于 2019-12-10 21:36:37
问题 I have a JFrame with a JPanel on it ( JPanel is private in JFrame ). Now I want to override JPanel by using paintComponent method. How can I do that? 回答1: When you create your instance of JPanel , (assuming you're doing it this way), do this: JPanel panel = new JPanel(){ @Override public void paintComponent(Graphics g){ // paint code } }; The other alternative is to create a private class which extends JPanel . For example: public class OuterClass{ // fields, constructors, methods etc..

Using a thread loop to update a JFrame

我的梦境 提交于 2019-12-10 21:02:23
问题 ive done some extensive searching on using threads in a loop and whilst I understand the concept how how seperate threads work, I still cant seem to grasp how to implement it in my simple application. My application consists of a form with a text box. This textbox needs to be updated once ever iteration of a loop. It starts with the press of a button but the loop should also finish with the press of a stop button. Ive used a boolean value to track if its been pressed. Here is my form code:

Java: Keep window fullscreen in second monitor when not focused

拟墨画扇 提交于 2019-12-10 20:24:57
问题 I am writing a java application that takes advantage of a dual monitor set up. I have two windows: Window 1 - Main GUI Window 2 - Full Screen on Second monitor My Problem: The second window only stays full screen when it has the focus. If I click back on window 1 or change the focus to something else, window 2 minimizes. Is there someway to make window 2 stay full screen when it doesn't have focus? Here is my code for making the second window full screen on the second monitor: frame

paintComponent is not working (Java)

瘦欲@ 提交于 2019-12-10 20:13:42
问题 I have been trying to override and use the paint component method instead of the paint method because I've seen it been suggested in multiple questions around here. I've looked through many questions but I still can't seem to get this to work. I'm posting my original piece of code used to render a screen. I am thinking that extending JFrame is not the right way to go and instead I need to extend JPanel, and use paint component from there. I have another object where I actually extend the

PaintComponent is not being called

别来无恙 提交于 2019-12-10 19:53:55
问题 I´m just starting to learn how to program so excuse me if my question is just silly. I have been trying for over two days to find a solution for this problem and I just can't find it over the net so I need your help. Thanks in advance. So, I am trying to recreate the Parchisi game in Java. I want to create a method that puts a counter in an specific position every time a player rolls the dice and obtains the number five as a result. The counter has its own class, that is: package parchis;

CardLayout (swing) with action listeners on buttons?

北战南征 提交于 2019-12-10 19:51:49
问题 I've been trying to figure out CardLayout with action listeners on button (so like - starts on a load-up page- and on a button click switches to a different "card" my code won't even run right now i'm not entirely sure why - most implementations I can find use ItemListeners and Combo Boxes The basic process I've done is create a master JPanel, but my cards JPanel onto the master JPanel, but my different cards into the cards JPanel, then add the master JPanel to the frame to display... Also,

How to minimize one panel out of four panel

自作多情 提交于 2019-12-10 19:01:41
问题 Why i am getting the errors in the abstract class.Earlier i thought there may be a class of the same so i have created a new package and created a class test but still i am getting the same error.Any Solutions to it. /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package newpackage; /** * * @author SriHari /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author SriHari */ import java.awt

Why My JComponent is not displayed on top of backgound JFrame?

南笙酒味 提交于 2019-12-10 18:09:20
问题 Why My JComponent is not displayed on top of backgound JFrame? Please check the following code: class CounterFrame extends JFrame { /** * */ private static final long serialVersionUID = 1L; private MyPanel myComponent = new MyPanel(); private JLabel contentPane = new JLabel(new ImageIcon(getClass() .getResource("background/2.jpg"))); CounterFrame() { contentPane.setLayout(new GridBagLayout()); setContentPane(contentPane); add(myComponent); } } class MyPanel extends JPanel { /** * */ private

how to set semi-transparent jframe when “submit” button is clicked?

岁酱吖の 提交于 2019-12-10 17:48:44
问题 loadingLab=new JLabel("The name is being saved.."); loadPanel.add(loadingLab); submitBttn=new JButton("Submit"); submitBttn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Submit Button Clicked!!"); try { //something is wrong in here as it throws an exception //what is wrong? frame.setUndecorated(false); frame.setOpacity(0.55f); //when above both lines are commented, the code works fine //but doesnt have transparency frame

Switching between screens in Java swing

妖精的绣舞 提交于 2019-12-10 17:25:25
问题 I had build big application for my client in Android. The new project is to build the same app for PC in Java. So i have started developing with use of swing. When building in Android i use classes with activities that had content views and i could switch between activities. In java i have build multiple classes that extends JFrame and i wish to switch between them. What is the right way to to this? is this: new_class.setVisible(true); old_class.setVisible(false); the correct way? 回答1: The