jpanel

How to dynamically remove a JPanel?

删除回忆录丶 提交于 2019-11-29 12:42:23
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 static int size=0; private int selectedId=-1; //private public Main(){ mpList=new ArrayList<myPanel>()

Background image in a nested JPanel?

寵の児 提交于 2019-11-29 12:41:17
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 image on the JPanel, and add some jlabels and text field on top of the JPanel and image later on. Here

Making a JPanel manually resizable

↘锁芯ラ 提交于 2019-11-29 12:24:41
问题 I have a JFrame with BorderLayout as the layout manager. In the south border, I have a JPanel , I want this JPanel 's size to be adjustable by the user, i.e. the user can click on the edge of the border and drag it up to make it larger. Is there any way you know that I can do this? 回答1: In order to make panels in a frame individually resizable you need to add them onto a JSplitPane. Instead of putting it in the South portion of the Frame, put the JSplitPane in the Center. The split pane will

How to Export JPanel with scrollable into pdf file

蓝咒 提交于 2019-11-29 12:21:41
i have design a jpanel with so many swing components with scrollable capability. i want to export whole Jpanle into pdf file.but i am not able to export whole Jpanle. I have use itext for pdf generation. My problem is that i am not able to export whole jpanel into pdf. When i export half of Jpanel components export.but half portion do not export. this is my code. public void PrintFrameToPDF(JPanel c, File file) { try { Document d = new Document(); PdfWriter writer = PdfWriter.getInstance(d, new FileOutputStream("F://newfile.pdf")); d.open(); PdfContentByte cb = writer.getDirectContent();

Draw the line on the Jpanel when dragging the mouse

你说的曾经没有我的故事 提交于 2019-11-29 12:03:25
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 Jpanel 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.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java

Why will BoxLayout not allow me to change the width of a JButton but let me change the height?

牧云@^-^@ 提交于 2019-11-29 12:00:20
问题 I'm trying to get the Layout of a JDialog of mine to fit a particular look that a program in which I'm porting to Java has, I've used several LayoutManagers before with great success yet for some reason I cannot seem to get this working at all. My goal is to have the Right (East) side of the JDialog contain a "Find Next" and "Cancel" button in a top-down order and then any extra space below so that the two buttons are always at the top of the JDialog , yet for some reason BoxLayout is

How to change the dimension of a component in a JFrame

陌路散爱 提交于 2019-11-29 11:57:14
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 FlowLayout() ); SomePanel somePanel = new SomePanel(); frame.add( somePanel ); frame.setVisible( true );

How do I hide the current JPanel and show a new one with a button in Java?

蹲街弑〆低调 提交于 2019-11-29 11:38:04
I unfortunately have to use multiple windows in this program and I don't think CardLayout is going to work because I can't have any buttons constant between the different layouts. So I'm trying to code a button to hide the present JPanel (thePanel) and show a new one (thePlacebo). I'm trying to hide thePanel in an ActionListener like this: frame.getContentPane().remove(thePanel); I thought this would work, but it just freezes my program as soon as I hit the button. Here's a chunk of the code for context: public class Reflexology1 extends JFrame{ JButton button1, button2; JButton movingButton;

Java setBounds not working with JPanel

穿精又带淫゛_ 提交于 2019-11-29 11:31:27
i am doing a small Gui in java. i am using setBounds methods to set the position of buttons etc on my JFrame , but problem is that when i use it with JPanel button is not visible on JFrame , and without JPanel its quite ok ,, see both the codes and please help me as i am beginner and facing these foolish problems . This one is working fine JFrame jframe = new JFrame("Working Fine"); jframe.setLayout(null); JButton jbutton = new JButton("Position Test"); jbutton.setBounds(0, 0, 100, 100); jframe.add(jbutton); jframe.setSize(300,300); jframe.setVisible(true); Same code when i add Button to

add component to jpanel on runtime

与世无争的帅哥 提交于 2019-11-29 11:21:24
I have a JPanel and JButton on the JFrame . on runtime add JLabel to JPanel When click JButton . I use of the following code: panel.setLayout(null); jLabel _lbl=new jLabel(); _lbl.setText("Label"); panel.add(_lbl); panel.validate(); but no display any JLabel in JPanel . I see you create a JLabel called _lbl : JLabel _lbl=new JLabel(); but you never add it to your panel. Instead you add a new JLabel with no text to your panel: panel.add(new JLabel()); This would ofcourse construct an empty label which wont be visible. Also try calling revalidate() and repaint() on your JPanel instance after