jpanel

How to draw in JPanel? (Swing/graphics Java)

会有一股神秘感。 提交于 2019-11-26 05:53:48
问题 I\'m working on a project in which I am trying to make a paint program. So far I\'ve used Netbeans to create a GUI and set up the program. As of right now I am able to call all the coordinated necessary to draw inside it but I am very confused with how to actually paint inside it. Towards the end of my code I have a failed attempt at drawing inside the panel. Can anyone explain/show how to use graphics in a example like this? All examples I have found make a class and extend it with JPanel

Simplest way to set image as JPanel background

让人想犯罪 __ 提交于 2019-11-26 05:49:43
问题 How would I add the backgroung image to my JPanel without creating a new class or method, but simply by inserting it along with the rest of the JPanel\'s attributes? I am trying to set a JPanel\'s background using an image, however, every example I find seems to suggest extending the panel with its own class. I have been looking for a way to simply add the image without creating a whole new class and within the same method (trying to keep things organized and simple). Here is an example of

animate JPanel (slide in) with timer

◇◆丶佛笑我妖孽 提交于 2019-11-26 05:39:25
问题 I am trying to make a JPanel slide in from the side using this class i made: public class AnimationClass { private int i; private int y; private JPanel panel; private int xTo; private Timer timer; private int xFrom; synchronized void slidePanelInFromRight(JPanel panelInput, int xFromInput, int xToInput, int yInput, int width, int height) { this.panel = panelInput; this.xFrom = xFromInput; this.xTo = xToInput; this.y = yInput; panel.setSize(width, height); timer = new Timer(0, new

Simplest way to set image as JPanel background

孤者浪人 提交于 2019-11-26 05:16:37
How would I add the backgroung image to my JPanel without creating a new class or method, but simply by inserting it along with the rest of the JPanel's attributes? I am trying to set a JPanel's background using an image, however, every example I find seems to suggest extending the panel with its own class. I have been looking for a way to simply add the image without creating a whole new class and within the same method (trying to keep things organized and simple). Here is an example of the method that sets my JPanel: public static JPanel drawGamePanel(){ //Create game panel and attributes

paintComponent() vs paint() and JPanel vs Canvas in a paintbrush-type GUI

邮差的信 提交于 2019-11-26 04:26:37
问题 I got some interesting ideas and criticism from this, this and this post (see last post for the code of the GUI in question). Nevertheless, I\'m still quite confused about some things. Mainly, what is the least expensive way of displaying user-introduces graphics? More specifically, I used a paintComponent() method from JPanel class by making an object of this class in the MouseDragged() method together with paintComponent(getGraphics()) method ( AuxClass2 and AuxClass1 accordingly).

JLabel - Show longer text as multiple lines?

为君一笑 提交于 2019-11-26 02:14:45
问题 So say I have a really long line that I want to display in a JLabel . How can I do it? Currently, longer lines come up as this: I have to resize the window to see the complete text. How can I make it so that there\'s linebreaks when the text almost reaches the width of my JFrame ? I\'m not sure if any code is required here for you to answer this, but still: my frame properties: frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(new Dimension(450, 400));

JPanel repaint issue

心已入冬 提交于 2019-11-26 02:13:59
I have a JFrame which contains 2 JPanel subclass and 2 JLabel in BorderLayout. One of the JPanel contains JButtons and the other is used for displaying graphics. The JLabels are in north and south, the button JPanel in the west and the display JPanel in center. The display JPanel requires constant refresh, so i invoke its repaint() method via the action event generated by swing timer. I also override its paintComponent() method to do my drawings. Instead of displaying what i have drawn, the "content of the JFrame" is being drawn onto the display JPanel. I am aware that i can simply "clear" the

JPanel & components change position automatically

雨燕双飞 提交于 2019-11-26 02:03:57
问题 Hi I am working on swing application but I am facing one problem. When I first run application JPanel is positioned at proper position where I decided to set with components inside. But problem occur when I minimize & again maximize frame window jpanel automatically changes it\'s position. Below images shows that difference As we can see on second image components changes it\'s position automatically. For this I written below code, jpanel_addPurchase = new JPanel(); jpanel_addPurchase

Add an Background image to a Panel

不羁岁月 提交于 2019-11-26 02:03:06
问题 I have a JPanel , and i want to add an image as its background. How can i do that ? frame = new JFrame(\"Some frame\"); panel1 = new JPanel(); panel1.setBorder(new EmptyBorder(5, 5, 5, 5)); // NEED TO ADD AN IMAGE TO THIS PANEL panel1.setLayout(cardlayout); frame.getContentPane().add(panel1); frame.setLocationByPlatform(true); frame.setVisible(true); I need to add an image to the panel and how can i do it ? UPDATE 1 panel1 = new JPanel() { private static final long serialVersionUID = 1L;

JPanel repaint issue

只谈情不闲聊 提交于 2019-11-26 01:09:20
问题 I have a JFrame which contains 2 JPanel subclass and 2 JLabel in BorderLayout. One of the JPanel contains JButtons and the other is used for displaying graphics. The JLabels are in north and south, the button JPanel in the west and the display JPanel in center. The display JPanel requires constant refresh, so i invoke its repaint() method via the action event generated by swing timer. I also override its paintComponent() method to do my drawings. Instead of displaying what i have drawn, the \