Okey now the problem is that if the previewFrame is set to the default layout the buttons show but since it is using a layout manager the setBounds,setLocation,setSize commands dont work. So I used the code previewFrame.setLoayout(null) which would let me set my own position of the buttons on the JFrame however when I run my program the JFrame is blank and is gray. Anyone know why?

Thanks in advance

static javax.swing.Timer slideTimer4 = new javax.swing.Timer(0100, new ActionListener() {
	
	public void actionPerformed(ActionEvent e) {
		
		previewFrame.setLayout(null);
		
		//restart preview button
		restartPreviewBtn.setLocation(10,10);
		restartPreviewBtn.setSize(80,80);
		restartPreviewBtn.setBackground(blackColor);
		restartPreviewBtn.addActionListener(new restartPreviewAction());
		finishPanel.add(restartPreviewBtn);
		
		//close previewFrame button
		closePreviewFrameBtn.setLocation(150,150);
		closePreviewFrameBtn.setSize(80,80);
		closePreviewFrameBtn.setBackground(blackColor);
		closePreviewFrameBtn.addActionListener(new closePreviewAction());	
		finishPanel.add(closePreviewFrameBtn);
		
		//finishPanel Properties
		finishPanel.setBackground(Color.BLACK);
		
		restartPreviewBtn.setVisible(true);
		closePreviewFrameBtn.setVisible(true);
		
		previewFrame.getContentPane().add(finishPanel);
		previewFrame.repaint();
		previewFrame.validate();
	}
});

Recommended Answers

All 4 Replies

I don't believe that you should hard-code positions of buttons onto frame's or panels unless you are somehow required to. You should ideally use a layout manager or combination of them to structure your frame - Can you briefly tell me how you want the buttons to be arranged without the buttons underlying coding posted? If so I can point you in the right direction

Hi Katana,

Sorry for the slow reply, been working on other parts of my program. At the moment all my JFrames have the buttons positions coded in as I find it easier since I dont have any experience with layout managers and they look structured as to where buttons, labels and ect are placed. However what this JFrame does it show a slideshow of images. Thats why it is in a swing.timer for, so once the images have been shown I want the close and restart button to show kind of central in the JFrame.

Thanks in advance Katana

It depends on how you want the buttons to appear - do you want the buttons to appear on top of the last image or for the image to disappear and then the buttons to appear in the centre?

Hi Katana,

These buttons will only appear after the slideshow has finished. So once the program has went through all the images the JFrame is just blank and colored black. Currently when using the previewFrame.setLayout(null); the JFrame becomes grey and does not show the buttons. But when I take that code out, it uses the default layout (dont know which one it is) and the buttons are not in the centre. If there is a layout that sets the buttons in the middle, dead centre of the JFrame that would be perfect. Thanks in advance Katana. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.