jpanel

I need to make my JPanel resize dynamically as new components are being added to it

独自空忆成欢 提交于 2019-12-01 11:18:40
问题 I need to let users add more text fields to my JFrame so once the size of the frame has exceeded its original value a scroll pane would step in. Since I cannot add JScrollPane to JFrame in order to enable scrolling I decided to put the JPanel on the JFrame and pass the JPanel object into the JScrollPane constructor. Scrolling now works fine but only until it has reached the borders of the JPanel. The thing is the size of JPanel stays as is and is not stretching dynamically. What happens is

Making Table With List Of JPanels

爷,独闯天下 提交于 2019-12-01 10:43:28
问题 I need to a table in Java application. First I used to a Object of class JTable but my table has a lot of features and at now I try to use a list of JPanel components instead a table. How can I make a table with a list of panels? 回答1: If you need to create a table composed of JPanel s containing JTextArea , start with something like: JPanel table = new JPanel(); table.setLayout(new BoxLayout(table, BoxLayout.X_AXIS)); for (int rowIndex = 0; rowIndex < numberOfRows; rowIndex++) { table.add

How to animate Rectangle in JPanel?

寵の児 提交于 2019-12-01 10:36:28
问题 I want to learn some tricks about JAVA for my project. I want to animate my Rectangle leftoright and righttoleft but I can't apply the same functions for ball animation. In addition,how can I start my ball in different x-direction with a border of y-coordinate ? Thanks a lot for your advices and helping. My codes: import javax.swing.Timer; import java.util.ArrayList; import java.awt.*; import javax.swing.*; import java.awt.event.*; public class MultipleBall extends JApplet { public

Java Swing: Access panel components from another class

浪子不回头ぞ 提交于 2019-12-01 10:29:36
Hi i basically have two classes, one main and one just to separate the panels, just for code readability really. i have : public class Main{ public static void main (String args[]) { JFrame mainJFrame; mainJFrame = new JFrame(); //some other code here CenterPanel centerPanel = new CenterPanel(); centerPanel.renderPanel(); mainFrame.add(centerPanel.getGUI()); } } class CenterPanel{ JPanel center = new JPanel(); public void renderPanel(){ JButton enterButton = new JButton("enter"); JButton exitButton = new JButton("exit"); center.add(exitButton); center.add(enterButton); } public JComponent

drawing shape objects in java (draggable,resizable and can rotate)

前提是你 提交于 2019-12-01 10:25:03
问题 I am trying to draw shapes (triangle, rectangle, square and circle) that can be used in creating a picture. A user should be able to place a shape on a canvas and drag it around or even enlarge it to create a desired picture. I tried overriding the paintComponent() of a JPanel to achieve this but realize that the Jpanels shape remains a square so when you have a circle you can still drag it even if u are not necessarily touching it as it is within a square and also having difficulty drawing

Drawing in JPanel vs JComponent

淺唱寂寞╮ 提交于 2019-12-01 09:58:50
问题 I need some help understanding why the drawing works differently in JComponent vs JPanel. import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel; public class Particle extends JComponent implements Runnable{ private int x = 45; private int y = 45; private int cx; private int cy; private int size; private Color color; private JFrame frame; public Color getColor(){ return color = new Color

How do I re run the paint method so the JPanel is animated?

和自甴很熟 提交于 2019-12-01 09:41:56
I think I need to put some code where the comment is (or maybe use non static method but I am not sure). The main method creates the window and then starts the graphics method. I would like the blue square to flash. import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class paintTest extends JPanel{ private static JFrame theWindow = new JFrame("Window"); static boolean blueSqr = false; public void paint(Graphics g) { g.setColor(Color.RED); g.fillRect(10, 10, 10, 10); if(blueSqr){ g.setColor(Color.BLUE); g.fillRect(10, 10, 10, 10); } }

Translucent components inside JPanel

梦想与她 提交于 2019-12-01 09:11:11
I have class MyPanel that extends from JPanel. MyPanel class has JLabel component which holds an icon. My question is how can i paint/render this JLabel component to get translucent effect (see through icon) inside MyPanel class (not create xxxJLabel extends JLabel class and override paintComponents method). Thank you Andrew Thompson One way is to provide a translucent image to the JLabel . That might be done with a standard label, before setIcon() or similar is called, or alternately by extending JLabel and overriding the setIcon() method to do the same. E.G. of 2nd technique Code import java

Translucent components inside JPanel

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 07:20:56
问题 I have class MyPanel that extends from JPanel. MyPanel class has JLabel component which holds an icon. My question is how can i paint/render this JLabel component to get translucent effect (see through icon) inside MyPanel class (not create xxxJLabel extends JLabel class and override paintComponents method). Thank you 回答1: One way is to provide a translucent image to the JLabel . That might be done with a standard label, before setIcon() or similar is called, or alternately by extending

Black square showing when adding a .GIF on JPanel

百般思念 提交于 2019-12-01 06:46:53
My problem is that when adding a .GIF to a JPanel, it shows this black square background for the .GIF. Result when adding on JPanel: It happens when I use this line: p2.add(loadBar); // where p2 = new JPanel(); However, when I add the same .GIF on the JFrame, the black square is not there anymore. Like this: jf.add(loadBar); // where jf = new JFrame(); Result when adding on JFrame: Part of the class code: String loadLink = "http://i.imgur.com/mHm6LYH.gif"; URL ajaxLoad = null; try { ajaxLoad = new URL(loadLink); } catch (MalformedURLException e3) { // TODO Auto-generated catch block e3