수정 사항은 아래를 참조하십시오.JFrame을 사용하여 Java Button의 위치를 설정하려고하지 않습니다.
내 문제를 해결하기 위해 수많은 "솔루션"을 살펴 보았지만 문제가 해결되지 않는 것 같습니다.
이는 기본적으로,이 버튼의 위치를 설정하려면,하지만 난 그렇게 할 관리 할 수 없습니다 :
이 내 응용 프로그램은 아래의 코드와 같은 모습입니다. 여기 내 코드입니다 :
package me.cervinakuy.application;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ControlPanel3 extends JFrame {
JPanel panel = new JPanel();
JButton startRobo = new JButton();
JButton stopRobo = new JButton();
JButton restartRobo = new JButton();
public ControlPanel3() {
// setLayout(null);
setSize(1000, 700);
setResizable(false);
setLocation(450, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setBackground(new Color(45, 48, 55));
setTitle("Espin Software | Control Panel");
setVisible(true);
startRobo.setIcon(new ImageIcon(getClass().getResource("/resources/startRobo.png")));
stopRobo.setIcon(new ImageIcon(getClass().getResource("/resources/stopRobo.png")));
restartRobo.setIcon(new ImageIcon(getClass().getResource("/resources/restartRobo.png")));
startRobo.setBorder(null);
stopRobo.setBorder(null);
restartRobo.setBorder(null);
startRobo.setLocation(100, 100);
panel.add(startRobo);
panel.add(stopRobo);
panel.add(restartRobo);
panel.setOpaque(false);
add(panel);
validate();
}
}
편집 : 지금은 처음 찾던의 GUI를 만들고 관리해야 그러나, 나는 새로운 문제가있다. 버튼은 이제 이미지가 아닌 GUI의 다른 부분에서 누를 수 있습니다. 관심있는 사람들을 위해, 여기에 내가 달성 할 수 있었던 것입니다 :
업데이트 코드 :
package me.cervinakuy.application;
import java.awt.Color;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class ControlPanel3 extends JFrame {
JPanel panel = new JPanel();
JButton startRobo = new JButton();
JButton stopRobo = new JButton();
JButton restartRobo = new JButton();
public ControlPanel3() {
// setLayout(null);
setSize(1000, 700);
setResizable(false);
setLocation(450, 150);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setBackground(new Color(45, 48, 55));
setTitle("Espin Software | Control Panel");
setVisible(true);
startRobo.setIcon(new ImageIcon(getClass().getResource("/resources/startRobo.png")));
stopRobo.setIcon(new ImageIcon(getClass().getResource("/resources/stopRobo.png")));
restartRobo.setIcon(new ImageIcon(getClass().getResource("/resources/restartRobo.png")));
startRobo.setBorder(null);
stopRobo.setBorder(null);
restartRobo.setBorder(null);
panel.setLayout(null);
startRobo.setLocation(200, 200);
startRobo.setBounds(5, -95, 300, 300);
stopRobo.setBounds(5, 0, 300, 300);
restartRobo.setBounds(5, 95, 300, 300);
panel.add(startRobo);
panel.add(stopRobo);
panel.add(restartRobo);
panel.setOpaque(false);
add(panel);
validate();
}
}
* 그들이) 도움이 실패한 이유 * 상위 5 링크 설명 "내 문제를 해결하는"솔루션 "나는 수많은 찾고했습니다", & b)는 당신을 설득한다는 데 실패 명시 적 위치를 설정 의 구성 요소는 역효과를 냈습니다. –
1) ASCII 아트 또는 최소 크기에서 GUI의 * 의도 된 * 레이아웃의 간단한 그림을 제공하고 크기를 조정할 수 있으면 더 많은 너비와 높이를 제공하십시오. 2) 더 나은 도움을 받으려면 [MCVE] 또는 [Short, Self Contained, Correct Example] (http://www.sscce.org/)를 게시하십시오. 3) 예를 들어 이미지를 얻는 한 가지 방법은 [이 Q & A] (http://stackoverflow.com/q/19209650/418556)에서 볼 수있는 이미지에 핫 링크하는 것입니다. –
나는 내 질문에 제목을 붙였을 때 처음 5 개를 이미 시도했지만, 처음 몇 개는 내가 성취하려고하는 것과 관련이 없으며, 나머지는 단순히 내 응용 프로그램 화면을 비워 두었습니다. 수많은 솔루션을 살펴 보았습니다. 의도 한 레이아웃은 매우 간단하며 왼쪽에 정렬됩니다. 그러나, 무엇인가의 이유로 그들은 모두 중앙에 위치하여 맨 위에 놓습니다. 나는 그들이 더 이상 존재하지 않게 위치를 설정하는 방법을 알아 내려고 노력하고있다. 따라서이 질문의 목적. – Espin