jpanel

Inclined plane Java (Triangle with angle)

落花浮王杯 提交于 2019-12-11 14:57:11
问题 i need to create an inclined plane according to a certain angle with a bloc on it and then use the physics laws to see if the bloc slides or not. For now, i created my bloc with a Path2D.Double, but i can't find a way to change the angle of the bloc. The angle is chosen from a spinner in the frame in the application.I created 2 class, one is the Frame, and the other is the Panel, where i draw my bloc. Here is the code of my path: @Override public void paintComponent(Graphics g) { super

Java problems with gif in label

亡梦爱人 提交于 2019-12-11 14:52:03
问题 A gif that I tried to put into a JPanel isn't showing up after clicking the button that triggers it until I resize the window. When it does show up, it does not fit the JPanel and is not animated. I looked at several posts that dealt with this but I don't understand how to use them in my case. /* * Author: Raymo111 * Date: 13/04/2018 * Description: Wishes happy birthday to a special someone */ //Imports java GUI classes import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*;

Moving left right in a JPanel

核能气质少年 提交于 2019-12-11 13:13:53
问题 I want to add a number of buttons to a JPanel dynamically, When I add it only shows a fixed number of buttons, So I would like to add a left right moving for viewing all buttons How we can do this, Is there any java component to do this? public class TestJPanel extends JFrame { JPanel statusBar; public TestJPanel() { setLayout(new BorderLayout()); statusBar = new JPanel(); statusBar.setLayout(new BoxLayout(statusBar, BoxLayout.LINE_AXIS)); add("South", statusBar); for (int i = 1; i < 20; i++)

Wrong JPanel displayed in CardLayout. Issues with getGraphics()

放肆的年华 提交于 2019-12-11 13:11:48
问题 I have a top-level GUI class called SpacePotaters (subclass of JFrame) and I add a JPanel called panelViews (which uses the CardLayout layout manager) to its content pane. Among other things, I add a MainMenu object (subclass of JPanel) and a GameView object (subclass of JPanel) as cards to panelView. public SpacePotaters(){ super("Space Potaters"); Container content = getContentPane(); // initialize components gameView = new GameView(this); mainMenu = new MainMenu(this); leaderboard = new

Center a JPanel in a JFrame

你说的曾经没有我的故事 提交于 2019-12-11 12:42:58
问题 How can I put my JPanel in the center of a JFrame without using a layout manager? I want it to be generic for all screen resolutions of course. Thanks, Tomer 回答1: If you don't use layouts ( setLayout(null) ), you need to calculate the location of the JPanel inside the JFrame , like: import java.awt.Color; import javax.swing.*; public class a extends JFrame { public a() { JPanel panel = new JPanel(); panel.setSize(200, 200); panel.setBackground(Color.RED); setSize(400, 400); // JFrame

How to get a JScrollPane to resize with its parent JPanel

做~自己de王妃 提交于 2019-12-11 12:42:50
问题 My question is similar to this one (How to get JScrollPanes within a JScrollPane to follow parent's resizing), but that question wasn't clear and the answer there didn't help me.. I have this SSCCE (using MigLayout): public static final int pref_height = 500; public static void main(String[] args) { JPanel innerPanel = new JPanel(new MigLayout()); innerPanel.setBorder(new LineBorder(Color.YELLOW, 5)); for(int i = 0; i < 15; i++) { JTextArea textArea = new JTextArea(); textArea.setColumns(20);

How to Draw a Transparent Background?

回眸只為那壹抹淺笑 提交于 2019-12-11 12:01:25
问题 I am trying to make a piece of a JPanel transparent, but I cannot quite get it to work. Is it possible to do this? import java.awt.*; import javax.swing.*; public class ClearPanel extends JPanel{ public static void main(String[] args) { ClearPanel c = new ClearPanel(); c.setPreferredSize(new Dimension(200, 200)); c.setOpaque(false); JPanel backPanel = new JPanel(); backPanel.setBackground(Color.CYAN); backPanel.add(c); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Removing a JPanel from a JFrame, so slow

你离开我真会死。 提交于 2019-12-11 11:35:03
问题 This is what the code looks like: class Main extends JFrame { public MyPanel panel; public Main() { //all the frame init stuff panel = new MyPanel(this); Panel badPanel = new Panel();//this makes the remove method go veryy slow //add(badPanel, BorderLayout.SOUTH);// JPanel goodPanel = new JPanel(); add(goodPanel, BorderLayout.SOUTH); // this fixes the slowness of the remove method in calculate() add(panel, BorderLayout.CENTER); } public static void main(String[] args) { SwingUtilities

JPanel Window not scaling when resize the main frame

点点圈 提交于 2019-12-11 11:28:36
问题 I was working on my code to draw a number of lines that the user inputted and the first end-point is centered at the y-coordinate while the second end-points are apart from each other by height/(number of lines the user entered). I verified my code and everything seems to be working fine except the fact that the JPanel does not scale as it should, corresponding to the size of the main frame. Can anyone please give me an advice? import java.awt.Graphics; import javax.swing.JPanel; import java

Scalable images in Java

北城以北 提交于 2019-12-11 11:27:52
问题 I anticipate using some images in my Java application. These images will be drawn onto my JPanel using g.drawImage() . The JPanel is resizable and the images should scale as the JPanel increases/decreases in size Two questions: What image format is best for this type of desired scalable image? For instance, in this application, an image of size 100x100 may be scaled into an image of size 30x30 or 10x10 or 300x300. How can I write code to do this scaling? 回答1: Take a look at Java: maintaining