jpanel

To Add Minimize /Maximize button to JDialog orJPanel

只谈情不闲聊 提交于 2019-11-28 08:07:30
问题 Is it possible to add maximize/minimize button to the JDialog? if not then can we add these buttons to JPanel? I have a JPanel and inside that panel there is a JDialog.I want to add a minimize/maximize button such that when that button is clicked JDialog and the components under JDialog get adjusted according to the JPanel. like when i click maximize then jpanel should get enlarged and components inside that panel(JDialog) also get enlarged and vice versa for minimize button. The solution I

adding multiple jPanels to jFrame

拟墨画扇 提交于 2019-11-28 07:41:48
I want to add two jPanels to a JFrame side by side. the two boxes are jpanels and the outer box is a jframe I have these lines of code. I have one class called seatinPanel that extends JPanel and inside this class I have a constructor and one method called utilityButtons that return a JPanel object. I want the utilityButtons JPanel to be on the right side. the code I have here only displays the utillityButtons JPanel when it runs. public guiCreator() { setTitle("Passenger Seats"); //setSize(500, 600); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = getContentPane();

How to prevent JLabel positions from resetting?

▼魔方 西西 提交于 2019-11-28 07:07:11
问题 I have a JPanel that contains 11 JLabels, each of them registered with a MouseMotionListener like so (generated by Netbeans): label1.addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseMotionEvent evt){ label1MouseDragged(evt); } and the individual labelXMouseDragged methods contain (for example): label1.setLocation(label1.getParent().getMousePosition()); This Panel lives inside another Panel alongside various other controls. I find that I can drag my labels just

Drawing 2 Balls to move in different direction on Java but one disappeared [closed]

半城伤御伤魂 提交于 2019-11-28 06:55:36
问题 I'm trying to create a program that would have 2 balls drawn, with one at the North center and the other at the south center. I am required to move the balls in different directions with the first ball at the North moving randomly towards south and the other ball at the south center to move towards the North. I can make the North Center ball move downwards but the second ball at the South disappears right after it is drawn. PS: I need to have 2 inner class which is Ball1 and Ball2 . Please

Background image in a nested JPanel?

家住魔仙堡 提交于 2019-11-28 06:33:59
问题 I have a JPanel which contains 2 more JPanel. Located on the left(leftBox) and the right(rB), I wanted to add a background image on the right JPanel (rB). But the result I get is http://i.imgur.com/tHz1x.jpg the result I wanted http://i.imgur.com/xHbpx.jpg public void paintComponent(Graphics g) { //this.paintComponent(g); if(wdimage != null) g.drawImage(wdimage,0,0,800,800,rB); //(image,location x, location y, size x, size y) } The rB Panel is blocking the image, what I want is to display the

How to dynamically remove a JPanel?

懵懂的女人 提交于 2019-11-28 06:29:36
问题 I have a a GUI looks as follow. I want to dynamically add/remove a panel. I use ArrayList to keep trace of JPanel objects. And now I could add panel dynamically, but when I want to delete a panel, I could not get its attribute so that I can not remove it. Here is my code: public class Main implements ActionListener{ private List <myPanel> mpList; private JPanel btnPanel; private JButton jbtAdd,jbtDelete; private JFrame jf; private JPanel jp; private JScrollPane js; private myPanel mp; private

How to change the dimension of a component in a JFrame

这一生的挚爱 提交于 2019-11-28 05:54:37
问题 Suppose I have a JPanel in a JFrame. When I invoke a method that changes the preferred size of that JPanel, it does not change. The code looks something like this: public class SomePanel extends JPanel{ public SomePanel(){ setPreferredSize( new Dimension( 390, 40 ) ); setBackground( Color.BLACK ); } public void expand(){ setPreferredSize( new Dimension( 390, 200 ) ); } public static void main( String args[] ){ JFrame frame = new JFrame(); frame.setSize( 450, 500 ); frame.setLayout( new

Draw the line on the JPanel when dragging the mouse

扶醉桌前 提交于 2019-11-28 05:40:10
问题 I want to draw 2 (or more ) lines on JPanel when the mouse drags. When i use super.paintComponent(g) in my code, I couldn't draw 2 lines on the panel, however when I don't use super.paintComponent(g); , the result is ugly, like the pic below : I understand why the lines behaved like that. How could I draw the lines on the panel when dragging the mouse? BTW, the line drawn by g2d.draw(line2d) sometimes it's not the smooth line (pic below) My codes so far : import java.awt.*; import java.awt

Components disappear after resizing JPanel

放肆的年华 提交于 2019-11-28 05:24:42
问题 I am trying to create JPanel with draggable crosses which appear after mouse clicking. Everything works fine but when I resize the JPanel the crosses disappear. I tried to override the paintComponent method in my JPanel but then all crosses are at coordinates (0,0). How can I fix it? import java.awt.*; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionAdapter; import java.util.ArrayList; import javax

How do I put graphics on a JPanel?

谁说胖子不能爱 提交于 2019-11-28 04:55:25
问题 I am having a problem adding graphics to a JPanel. If I change the line from panel.add(new graphics()); to frame.add(new graphics()); and do not add the JPanel to the JFrame, the black rectangle appears on the JFrame. I just cannot get the black rectangle to appear on the JPannel and was wondering if someone could help me with this. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Catch{ public class graphics extends JComponent{ public void paintComponent