jpanel

Setting the pivot point of a JPanel to its center

女生的网名这么多〃 提交于 2019-12-12 03:16:43
问题 I am building a Java application that is going to feature two circles of random sizes that need to be clicked by the user. The time between the click on the first and the second circle is going to be measured. Unfortunately, since I am new to Java so things have been slow for me. Currently I have my application draw circles and measure time between clicks using System.nanoTime() but now I am running into a problem. Because the circles need to be a fixed distance away from eachother I want to

Create a disappearing JPanel?

白昼怎懂夜的黑 提交于 2019-12-12 03:14:19
问题 I am trying to create an extended JPanel that acts as a way to highlight some region of the screen. I have taken some code from this SO answer but would like to extend it further though I am not sure how to go about it. I would like to be able to have my JPanel ( MatchAreaPanel below) disappear after a given timeout is reached. That is the JPanel sets its visible property to false and subsequently disposes of itself. What would be the best way to go about doing this? import java.awt

Java Swing — Jpanel with Jbuttons embedded within a JTable

南笙酒味 提交于 2019-12-12 03:11:02
问题 Im building a Ui in Swing wherein my requirement is to have JPanes within a JTable. These JPanes will have JButtons within them. My use case is as follows -- Im writing a MethodEditor wherein im providing a UI to store the methods within a supplied file. The UI would also allow editing the parameters being passed to the method on the click of a button. Every single method would have a UI representation as follows -- My basic representation of the Method class is as follows -- public Class

Change content pane on button press

一曲冷凌霜 提交于 2019-12-12 03:03:27
问题 I want a button to change the contentPane in a frame. An admin panel and a user panel in two different JPanel classes that gets called in a MainWindow class with a frame. My code looks as follows: The method the button calls: public void ChangeContent() throws Exception{ MainWindow mw = new MainWindow(); AdminUI admin = new AdminUI (); mw.frame.getContentPane().removeAll(); mw.frame.setContentPane(admin); mw.frame.revalidate(); mw.frame.repaint(); } This is the method being called in my

How can I resize the charts on a JFrame automatically?

一曲冷凌霜 提交于 2019-12-12 03:02:59
问题 I have wrote a code that creates two scatters and two JPanels placed on a JFrame. However I could not make them fit automatically to the size of the window when it is being resized. Here is the code for one of the drawing classes: class ALTCanvas extends JPanel{ private static final long serialVersionUID = 1L; private XYSeries alts = new XYSeries("Altitude"); public ALTCanvas() { final ChartPanel chartPanel = createDemoPanel(); this.add(chartPanel, BorderLayout.CENTER); } private void update

NullPointerException when trying to use method from custom JPanel

筅森魡賤 提交于 2019-12-12 02:49:44
问题 I am trying to make a GUI for my game I created a while back, and I am running into a slight issue while running it. I want to have the output print to a JTextField in an extended JPanel. However, when I run it, it comes up with this error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Classic.print(Classic.java:509) at Classic.play(Classic.java:43) at Karma.actionPerformed(Karma.java:134) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)

Make background image show through panels on top

落花浮王杯 提交于 2019-12-12 02:33:43
问题 When I add panels and objects in panels, I want the image to be set as the background and show through the panels put on top of it. I read you can do this bet setting the panel.setOpaque(false) option, however this does not seem to work. Here is my compiler directory and how it's setup (Using Intellij)... Here is the background Image... Here is the code... BackgroundPanel class > http://www.camick.com/java/source/BackgroundPanel.java /** * Created by James Page on 4/16/2017. */ package Main;

java JFrame scaled UI display with virtual drawing space

情到浓时终转凉″ 提交于 2019-12-12 02:28:43
问题 i have an application that has graphics which are thought to be displayed at 1024x768. I want to make the application flexible in size without rewriting all drawing code, position calculation etc.. To achieve that my attempt was overriding the paint method of the JFrame container in the following way: @Override public void paint(Graphics g) { BufferedImage img = new BufferedImage(this.desiredWidth, this.desiredHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D gi = (Graphics2D) img.getGraphics(

Change class that extends JFrame to class that extends JPanel

冷暖自知 提交于 2019-12-12 02:08:43
问题 I'm a Java-Newbie an I'm trying to build my first app. I read lots of tutorials and demos and searched for concrete answers to my question but haven't found something that helps. For testing I wrote this class, that connects an access database with a JTable. Now I want to add this Class in a main app but therefore i have to change my exisiting class to JPanel. I tested some changes, but I don't get an output JTable inside my app anymore. Can anybody explain the way I have to change my class?

Java Change shape of JPanel

冷暖自知 提交于 2019-12-12 02:05:56
问题 I'm trying to do something which I'd think would be fairly easy but can't find a straight forward answer to. Basically I want to change a JPanel's default shape to a circular shape (or any other shape other than a rectangle). 回答1: You will need to provide your own custom painting routines. The other problem you will have is getting the layout managers to work with it, but you can supply your own insets to provided an area within the panel that can safely used You'll also want to make the