먼저 Oracle Java 문서 & 자습서를 약 6 번 읽었으니 안심 하셔도됩니다. 도움이된다면 오라클 페이지에 대한 링크를 제공하는 것보다 더 잘해야 할 것입니다. 죄송합니다.jLabel에 String을 표시하려면 어떻게합니까?
분명히 나는 Strings의 작동 방식을 모릅니다. 4 jButtons 밀어 넣을 때 문자열을 자신의 값을 보낼 얻으려고 노력하고있어, 그 마지막 단추 만 그 문자열 또는 값을 (이름, 텍스트, 어떤 작품) 기록됩니다 그렇게 연결할 수 있습니다. 값을 jLabel의 메시지에 추가합니다.
여기에는 2 가지 문제가 있습니다. "상태"버튼을 올바르게 설정하지 않아야하며 값을 가져 와서 jLabel에 넣을 수 있어야합니다.
당신은 내가이 스크린 샷을보고 붙어있어 여기서 볼 수 있습니다 : 그것은 "로드 대신 4"상태 "버튼 ("배송 "1의 값의"널 (null) "라고하거나 위치를 확인 http://krisbunda.com/gui2.png
"등)
private void shippedButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
StringBuilder status = new StringBuilder(loadedButton.getText());
}
private void loadedButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
StringBuilder status = new StringBuilder(loadedButton.getText());
}
private void outReadyButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
StringBuilder status = new StringBuilder(outsideReadyButton.getText());
}
private void outNotReadyButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
StringBuilder status = new StringBuilder(outsideNotReadyButton.getText());
}
private void enterButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Confirmation.setVisible(true);
Confirmation.setBounds(300,200,900,400);
Confirmation.setModal(rootPaneCheckingEnabled);
confirmationLabel.setText("You are about to send this message:"
+ "\n #" + display.getText()+ " is currently " + status);
}
private void confirmationNoButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Confirmation.dispose();
}
모든 도움을 주시면 감사하겠습니다.
편집 : 도움을
덕분에, 여기에 내가 "새로운 라인"문제에 대한 파악 해결 방법입니다 : 나는 2 JLabels을 사용했다.
등과 같은 코드 : 여기
private void enterButtonHandler(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Confirmation.setVisible(true);
Confirmation.setBounds(200,300,1000,400);
Confirmation.setModal(rootPaneCheckingEnabled);
confirmationLabel1.setText("You are about to send this message:");
confirmationLabel2.setText("PS# " + display.getText()+ " is currently " + status);
}
과 "뱀장어의 호버 전체"응답 수정 프로그램을 설명하기 위해 코드의 조각을이다 :
1) 비 지역 변수를 추가/문자열 :
public class PlanterStatusUI extends javax.swing.JFrame
{
/** Creates new form PlanterStatusUI */
public PlanterStatusUI() {
initComponents();
}
public String status = new String(); {
}
2) 변경 버튼 코드 :
그냥 프로그램을 실행하면 효과가 있습니다. 도와 주셔서 감사합니다! 당신이 아직 그곳에 있다면 "새로운 라인"을 설정하는 또 다른 질문이 있습니까? "\ n"이 (가) 나를 위해 작동하지 않습니다 ... – Kris
html을 사용해야합니다 ... html로 사용하려면
을 사용해야합니다. http://download.oracle.com/javase/tutorial /uiswing/components/html.html –
여러 줄로 된 JLabel을 원할 경우 eugener를 사용하여 html 사용에 대해 들어보십시오. 그러나 몇 줄 이상의 데이터를 표시하려는 경우 JScrollPane의 JTextArea에 표시하는 것이 좋습니다. –