jpanel

How do I re run the paint method so the JPanel is animated?

无人久伴 提交于 2019-12-19 09:49:35
问题 I think I need to put some code where the comment is (or maybe use non static method but I am not sure). The main method creates the window and then starts the graphics method. I would like the blue square to flash. import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class paintTest extends JPanel{ private static JFrame theWindow = new JFrame("Window"); static boolean blueSqr = false; public void paint(Graphics g) { g.setColor(Color

making a JPanel into a JOptionPane.OK_OPTION

 ̄綄美尐妖づ 提交于 2019-12-19 09:47:04
问题 currently i have a class which extends JPanel and basically shows some information about an object passed into its constructor. There are various labels and Image icons on the screen and has a BorderLayout set. This panel is triggered when the user left clicks on an ImageIcon from the main GUI and shows up on the screen. i was wondering, how (if there is a way) i could implement the JOptionPane.OK_OPTION onto the whole Panel so that i dont have to close the panel using Event handling, as the

Giving a JPanel a percentage-based width

梦想的初衷 提交于 2019-12-19 09:41:16
问题 What's the easiest way to make a JPanel that takes up a fixed percentage of its parent container, by width? Its width should update when that of its parent container changes. I tried using Box.createHorizontalStrut() , but that doesn't update when the width of the JPanel 's parent container changes. 回答1: What you want is a GridBagLayout. (How to use?) Using a GridbagLayout allows you to define GridBagConstraints for each single component you add. These constraints include weightx which does

Bring JPanel to front of other objects in java (SWING)

做~自己de王妃 提交于 2019-12-19 07:54:50
问题 I want to make a loading message when an app processes, so I used a JPanel over a JTree . But when the user clicks on the JPanel , the JTree will be selected and the JPanel will go to the back. After hiding the JPanel , it never shows again. I don't know why, but it seems it never go in front of the JTree . I need a way to bring the JPanel in front of everything. How can I do this? EDIT: Also I must mention that I don't want a JDialog . I want to use the JPanel on top of any element to show a

Bring JPanel to front of other objects in java (SWING)

喜夏-厌秋 提交于 2019-12-19 07:54:30
问题 I want to make a loading message when an app processes, so I used a JPanel over a JTree . But when the user clicks on the JPanel , the JTree will be selected and the JPanel will go to the back. After hiding the JPanel , it never shows again. I don't know why, but it seems it never go in front of the JTree . I need a way to bring the JPanel in front of everything. How can I do this? EDIT: Also I must mention that I don't want a JDialog . I want to use the JPanel on top of any element to show a

JPanel custom drawing using Graphics

*爱你&永不变心* 提交于 2019-12-19 07:32:31
问题 I have a custom JPanel and sometimes throughout my program, I need to call a method which paints the screen black, that's it. public void clearScreen() { Graphics g = getGraphics(); g.setColor(Color.black); g.fillRect(0,0,getWidth(),getHeight()); } When I launch the program, I call this method. However, I find that sometimes it works, and sometimes it doesn't. It's very odd. I also found out that when it doesn't work, the graphics object is NOT null, and the width and height are also

How to replace JPanel with another JPanel

雨燕双飞 提交于 2019-12-19 03:07:19
问题 I want to replace a Jpanel with another one in a JFrame I already search and try my code but nothing's happen this is my code : public class Frame extends JFrame { private Container contain; private JPanel reChange,reChange2; private JButton reChangeButton; public Frame() { super("Change a panel"); setSize(350, 350); setLayout(null); setLocationRelativeTo(null); setResizable(false); reChange = new JPanel(null); reChange.setBackground(Color.red); reChange.setSize(240, 225); reChange.setBounds

Java MouseEvent position is inaccurate

耗尽温柔 提交于 2019-12-18 18:27:06
问题 I've got a problem in Java using a "canvas" class I created, which is an extended JPanel , to draw an animated ring chart. This chart is using a MouseListener to fetch click events. The problem is that the mouse position does not seem to be accurate, meaning it does not seem to be relative to the "canvas" but instead relative to the window (in the left, upper corner I got about 30px for y coord). This is my code: I created a class, that extends JPanel and does have a BufferedImage as member.

How to render basic HTML markup inside a JPanel in Java Swing?

烂漫一生 提交于 2019-12-18 13:37:20
问题 I want to do something really simple like this: JPanel htmlPanel = new HtmlPanel("<html><body><h1>hello world</h1></body></html>"); I think I had seen code somewhere that did exactly this. What about CSS and JS? Can the JPanel be made to support this easily? Are there libraries somewhere that do what I am asking for? 回答1: Check here to see how to add CSS support to your JEditorPane . You will need an HTMLEditorKit. I do not see why you would need JavaScript support for a JEditorPane. The

How can I paint in an specific JPanel when more than one in same frame- Java

元气小坏坏 提交于 2019-12-18 09:54:10
问题 Updated - this is related with the following link I posted yesterday. https://stackoverflow.com/questions/15916360/swing-gui-application-in-java-with-multiple-frames I apologize if I am doing something wrong here, I tried to write in my previous post and I couldn't find a way to do it beyond the comments box. I did some changes on my code, now I am working with 3 JPanels. I created a class for each panel except the main one that will hold in a CardLayout the other two. The main panel is