jpanel

JPanel setBackground(Color.BLACK) does nothing

独自空忆成欢 提交于 2019-12-01 01:03:18
问题 I have the folowing custom JPanel and I have aded it to my frame using Netbeans GUI builder but the background won't change! I can see the circle, drawing with g.fillOval(). What's wrong? public class Board extends JPanel{ private Player player; public Board(){ setOpaque(false); setBackground(Color.BLACK); } public void paintComponent(Graphics g){ super.paintComponent(g); g.setColor(Color.red); g.fillOval(player.getxCenter(), player.getyCenter(), player.getRadius(), player.getRadius()); }

JFrame : Getting actual content size

此生再无相见时 提交于 2019-12-01 00:48:54
问题 I have created a JFrame, and attempting to get it's size is giving an incorrect result, compared to what I expect. I have determined that it is including the operating system borders around the edges, and the title bar. How can I get/set the real size which I have available for rendering? 回答1: The size you are getting is the size of the content and the size of the insets. If you use Jcomponent.getInsets(), you can find the size of the content with simple subtraction. 回答2: Your question is

Dynamically remove Component from JPanel

不打扰是莪最后的温柔 提交于 2019-12-01 00:11:21
问题 I am adding and deleting components dynamically in a JPanel . Adding and deleting functionality works fine but when I delete the component it deletes the last component rather than the component to be deleted. How can I solve this issue? 回答1: Interestingly enough I am coming across the same issue and I am surprised people are upvoting the other answer, as he is clearly asking about dynamically created Components, not components already created under a variable name which is obtainable,

How do I know if I'm on the event dispatch thread?

一世执手 提交于 2019-11-30 23:11:22
问题 1.Consider my code is on some line of a JPanel that I have, am I automatically on EDT? 2.Same question for all other classes which are not belong to GUI, JPanels or other view classes, simple logical class. 3.If I have JPanel which I'm playing music while being in it, should the music run on event dispatch thread or on other thread which is not EDT (for not blocking the GUI, although I didn't feel any problem with running it from EDT)? Note: I want a general rule how to know it without using

How to overlay, resize and centre a component on a JPanel?

穿精又带淫゛_ 提交于 2019-11-30 21:15:43
I've spent a while reading and experimenting here, and come up with a few approaches, but not got any of them to work completely yet, so I would like to know what more experienced Swing programmers would do. The main window of my application contains a custom subtype of JPanel, which is used to display an image calculated from a mathematical function. This can take some time to calculate, so while this happens I display a text message and a progress bar superimposed on the middle of the panel. I would like both the text and the progress bar to resize appropriately when the panel is resized,

How to replace JPanel with another JPanel

 ̄綄美尐妖づ 提交于 2019-11-30 20:54:34
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(50, 50, 240, 225); add(reChange); reChangeButton = new JButton("Change It"); reChangeButton.setBounds

Java MouseEvent position is inaccurate

社会主义新天地 提交于 2019-11-30 16:56:43
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. public class Canvas extends JPanel { public BufferedImage buf; private RingChart _parent; public Canvas

Scrollable JPanel

故事扮演 提交于 2019-11-30 11:27:16
How to make a JPanel scrollable? I implemented the scrollable interface yet when adding it to the containing panel with tabbedPane.add("Editor", new JScrollPane(storeyEditor = new MNScrollablePanel())); nothing works Code: public class MNScrollablePanel extends JPanel implements Scrollable { public Dimension getPreferredScrollableViewportSize() { return getPreferredSize(); } public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { return 10; } public boolean getScrollableTracksViewportHeight() { return false; } public boolean

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

a 夏天 提交于 2019-11-30 10:01:51
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? 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 basic use of it is to render Help pages written in HTML and CSS. If you need to have the real McCoy embedded

Update normal distribution graph using JTextField in JFreeChart

拈花ヽ惹草 提交于 2019-11-30 09:34:21
问题 I have a class that extends JPanel for JFreeChart . Inside of setMean() , I tried updating values of dataset or just the Function2D , but nothing changes on the graph even with repaint() . public class JFreeChartPanel extends JPanel { Function2D normal = new NormalDistributionFunction2D(0.0, 3.0); XYDataset dataset = DatasetUtilities.sampleFunction2D(normal, -5.0, 5.0, 100, "Normal"); double mean = 0.0, std = 1.0; public double getMean() { return mean; } public void setMean(double mean) {