jpanel

Add GraphStream graph into my custom jPanel

混江龙づ霸主 提交于 2019-12-02 06:49:10
I am working on GraphStream library. For now, When I run my program it opens new window for my graph and separate window for my graph. I tried to create a JFrame and add JPanel into JFrame , after all this I tried to add graph into my JPanel but it says that graph object is not a component. Here is my code: import java.awt.BorderLayout; import java.awt.EventQueue; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border

java swing - how to change window background

懵懂的女人 提交于 2019-12-02 06:47:25
问题 I was trying to make a button that switches the window background from default to red. I haven't found any preset colors to match the default so i tried to get it from panel.getBackground when i created it. I have an error at line 11 , i don't know how to check the current background color. JPanel panel = new JPanel(); panel.setBounds(0, 0, 434, 262); frame.getContentPane().add(panel); panel.setLayout(null); panel.setVisible(true); Color c=panel.getBackground(); JButton btnRed = new JButton(

Adding an image to a JPanel background

橙三吉。 提交于 2019-12-02 06:35:53
问题 How can I add an image to a JPanel background. The image will not be scaled or resized. Thanks. 回答1: /** * @author * */ public class ImagePanel extends JPanel { private Image image = null; public ImagePanel(String filename) { this.image = new ImageIcon(filename).getImage(); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(image, 0, 0, image.getWidth(null), image.getHeight(null), null); } /** * @param args */ public static void main(String[] args) {

How to stop the auto-repaint() when I resize the Jframe

a 夏天 提交于 2019-12-02 06:35:47
问题 I am still learning Java, if someone can help me I will be very happy! Sorry for bad english, I am spanish! I am making a tile game, the game uses the classic "game loop" that cap the engine at 60fps The loop sleep and then call repaint(); This works fine! But.. The problem is that repaint event is called when the JFrame is resized or maximized! For example when the JFrame is maximized/resized the game render at 10000fps but when they dont, the game render at the speed I set, so there is a

How to draw a spiderchart above a existing JfreeChart

心已入冬 提交于 2019-12-02 06:00:28
问题 I have one a jfree chart which I can generate everytime I run the code. Now i want to override few more spider graphs on the same chart. please help me how to do that Above this i need to add one more spider chart using jfree. Here is my code for doing this chart. package com.rectrix.exide.pdfbox; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.GradientPaint; import java.awt.Paint; import java.awt.PaintContext; import java

java swing - how to change window background

ぐ巨炮叔叔 提交于 2019-12-02 05:48:57
I was trying to make a button that switches the window background from default to red. I haven't found any preset colors to match the default so i tried to get it from panel.getBackground when i created it. I have an error at line 11 , i don't know how to check the current background color. JPanel panel = new JPanel(); panel.setBounds(0, 0, 434, 262); frame.getContentPane().add(panel); panel.setLayout(null); panel.setVisible(true); Color c=panel.getBackground(); JButton btnRed = new JButton("Red"); btnRed.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if

Add multiple Polygon objects on the same JPanel frame

Deadly 提交于 2019-12-02 05:46:40
问题 So I have a DrawStar class that draws a star using Polygon like that: public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; int[] cX = new int[] {x, x+5, x+20, x+8, x+16, x, x-16, x-8, x-20, x-5, x}; int[] cY = new int[] {y, y+14, y+14, y+22, y+39, y+29, y+39, y+22, y+14, y+14, y}; Polygon pol = new Polygon(cX, cY, 11); g2.setColor(this.color); g2.draw(pol); g2.fillPolygon(pol); } Then in my main class I create a JPanel frame to draw the stars: ... JFrame starsframe = new

Rotate rectangle and move it in sin wave - Help using graphics2D

南楼画角 提交于 2019-12-02 05:40:58
问题 Hi! I have the code below using previous Stackoverflow posts. I want to just rotate the rectangle by some angle and make it move in sin wave. This code rotates the whole sin wave too. I understand why it is happening , but I don't know how to achieve my intention. please help!!! Thanks a lot for taking time. import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java

What is the correct way to use JPanels in Netbeans?

耗尽温柔 提交于 2019-12-02 05:27:44
I'm new to Java GUI. First I created a JFrame and have added a JPanel. After that I set it as a Null Layout. Then added a label and set a background image for the frame. For my project I need to add separate 4 JPanels for this JFrame. On those JPanels I'm going to add Labels and Text boxes. I want to know whether it's correct or not to add 4 JPanels on a main JPanel? Andrew Thompson I want to know whether it's correct or not to add 4 JPanels on a main JPanel? Sure. Most of the Java GUIs you see that are any more than trivial put panels inside other panels. Sometimes a different panel is used

How to draw on JPanel on fixed position?

大兔子大兔子 提交于 2019-12-02 05:23:49
I have JPanel wrapped in JScrollPane and I want the rectangle to be drawn always on the same position = moving with scrollbars wont affect the visibility of the rectangle. I tried following code: public void paintComponent(Graphics g) { g.setColor(Color.red); g.drawRect(50, (int)getVisibleRect().getY(), 20 , 20); } but it only repaints the rectangle when size of whole JPanel is changed. IIRC, JScrollPane will try to minimise the amount of redrawing done scrolling, so it wont always cause your component to be updated. The standard technique is to use a JLayeredPane . Add you JScrollPane to a