jpanel

Adding a ChartPanel to JPanel

怎甘沉沦 提交于 2019-12-10 22:49:36
问题 I've got some not working code here: XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.HORIZONTAL, true, true, true); ChartPanel chartpanel = new ChartPanel(chart); chartpanel.setDomainZoomable(true); jPanel4.setLayout(new BorderLayout()); jPanel4.add(chartpanel, BorderLayout.NORTH); So the problem is that the jPanel4 with a chart is not visible. When I add my

User input causes frame.getContentPane.removeAll() to stop working

眉间皱痕 提交于 2019-12-10 22:39:09
问题 Within a JFrame , i am replacing a Jpanel with another JPanel . package testing; import java.io.*; import java.util.*; import java.security.*; import javax.xml.bind.DatatypeConverter; import java.lang.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Testing extends JPanel { JLabel jl; ImageIcon icon; Point pointer; public static void main(String[] args) { JFrame jf = new JFrame(); JPanel jp1 = new JPanel(); JPanel jp2 = new JPanel(); JLabel jl1 = new JLabel(

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..

How to make Components align to the TOP in JPanel with BoxLayout?

烈酒焚心 提交于 2019-12-10 21:33:49
问题 I'm developing a game called GalaxyWar, and I am trying to make a map selection menu. I found a problem that when I am using a BoxLayout with BoxLayout.Y_AXIS on a JPanel with setAlignmentX(CENTER_ALIGNMENT) , the subcomponents (JPanel's) with assigned size, take up the entire height of the panel (all together), instead of the assigned height! Here is my code: scrollPane = new JScrollPane(); scrollPane.setBounds(160, 11, 452, 307); add(scrollPane); mapContainer = new JPanel(); mapContainer

GridLayout Removing Padding between JPanels

夙愿已清 提交于 2019-12-10 21:30:32
问题 I'm working on a Computer Science project, and I haven't been able to find any solution to my problem. I'm creating a 2D array of JPanel s containing images through a GridLayout . I want to remove the padding/margins between all the panels so that it flows seemlessly into a single image. However, the setHGap and setVGap methods don't seem to help me. I'd appreciate any response. Thank you. import java.awt.GridLayout; import java.util.Map; import javax.swing.ImageIcon; import javax.swing

Making a JPanel square

限于喜欢 提交于 2019-12-10 20:45:19
问题 If I have a JPanel with multiple subcomponents, how would I make it so that JPanel remains a square despite how its parent is resized? I have tried variations on the following code, but it does not result in the subcomponents also being square. public void paint(Graphics g){ if(this.isSquare()){ Dimension d = this.getSize(); if(d.height > d.width){ this.setSize(d.width, d.width); } else { this.setSize(d.height, d.height); } super.paint(g); } Here is an SSCCE. The containing parent: import

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;

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

How to make a component invisible, without changing the location of other elements

我怕爱的太早我们不能终老 提交于 2019-12-10 18:40:20
问题 There are two buttons: "Next" & "Back" to pass on the list. When the reached the end, the button "Next" to disappear, but the button "back" should not jump to her place. I use the setVisible (false) , but the button 'Back' jump to the place of the "Next". Location manager is GridBagLayout. 回答1: Place the button in a container JPanel with CardLayout together with one more empty JPanel (or JLabel). When you would like to hide the button just swap cards in the container. 回答2: I use the

Draw custom stuff on top of opaque components in a JPanel

旧街凉风 提交于 2019-12-10 18:37:28
问题 I have an JPanel populated with several opaque custom components. Now I would like to draw something on top of these components by overriding the paintComponent() method. My problem is that the painted stuff is placed behind the embedded components and, as they are opaque, is covered by them. Is there any way to let the painting appear on top of the components? Here's a short example of what I'm trying to do: public class DrawOnTop { public static void main(String[] args) { SwingUtilities