[완료] 자바 AWT/Swing 질문입니다.

GunSmoke의 이미지

입문서 보고 나서 직접 예제를 만들어보려고 했는데 일단 GUI부터 마음대로 제어하지 못해서 고생하고 있습니다. 쩝~

코드부터 보시죠.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
 
public class Practice {
 
    private JFrame theFrame;
    private ArrayList textFieldList;
    private JPanel mainPanel;
 
    private String [] row = {"0", "10", "20", "30", "40", "50", "60", "70", "80", "90"};
    private String [] col = {"90", "80", "70", "60", "50", "40", "30", "20", "10", "0"};
 
    public void buildGUI() {
        theFrame = new JFrame("연습");
        theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        BorderLayout layout = new BorderLayout();
	JPanel background = new JPanel(layout);
	background.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
 
	textFieldList = new ArrayList();
 
	Box colName = new Box(BoxLayout.X_AXIS);
        colName.add(new Label());
	for (int i = 0; i < 10; i++) {
		colName.add(new Label(col[i]));
	}
 
 
	Box rowName = new Box(BoxLayout.Y_AXIS);
	for (int i = 0; i < 10; i++) {
		rowName.add(new Label(row[i]));
	}
 
	background.add(BorderLayout.NORTH, colName);
	background.add(BorderLayout.WEST, rowName);
 
	theFrame.getContentPane().add(background);
 
	GridLayout grid = new GridLayout(10, 10);
	grid.setVgap(1);
	grid.setHgap(2);
	mainPanel = new JPanel(grid);
	background.add(BorderLayout.CENTER, mainPanel);
 
	for (int i = 0; i < 100; i++) {
		TextField c = new TextField();
		textFieldList.add(c);
		mainPanel.add(c);
	}
 
	theFrame.setBounds(50, 50, 500, 500);
	theFrame.pack();
	theFrame.setVisible(true);
    }
 
    public static void main (String [] args) {
        new Practice().buildGUI();
    }
}

이 예제의 실행 결과는 이렇습니다.

colName과 rowName이 각각 BorderLayout.NORTH와 BorderLayout.WEST로 지정되어 있기 때문에 윗쪽 Box와 왼쪽 아래 Box, 오른쪽 아래 mainPanel이 모두 따로 놀고 있습니다.

원하는 출력결과는 이렇게 윗쪽 Box와 왼쪽 아래 Box가 mainPanel을 기준으로 줄이 딱딱 맞아주는 건데 좋은 방법 없을까요?

File attachments: 
첨부파일 크기
Image icon cap01.JPG5.08 KB
Image icon cap02.JPG24.8 KB
Image icon cap03.JPG20.94 KB
cogniti의 이미지

Label을 GridLayout (11 * 11)에 모두 넣으세요.
단 칼에 해결됩니다.

GunSmoke의 이미지

아직 해보지는 않았지만...
어젯밤에 테스트할때 이런 식으로 해봤거든요? GridLayout을 2*2로 줘서 오른쪽 위에 Label, 왼쪽 아래에 Label, 오른쪽 아래에 TextFiled를 넣으면 되겠다 싶었습니다. 그러니까... 결과가 이렇게 나와버리더군요.

그리고 Label을 TextField랑 섞어서 넣지 않으려는 이유는 ArrayList에서 따로 관리하고 싶어서 그렇습니다.

大逆戰

댓글 첨부 파일: 
첨부파일 크기
Image icon sss.JPG0바이트

大逆戰

bookgekgom의 이미지

섞는다고 어레이리스트에서 관리가 안되는건 아닐텐데요...

윗분 말대로 하시죠?

아니면

setLayout(null);

해준뒤에 픽셀단위로 세세하게 고치셔야 합니다..

즐자바

---------------------------------------------------------------------------------------------------------------
루비 온 레일즈로 만들고 있는 홈페이지 입니다.

http://jihwankim.co.nr

여러 프로그램 소스들이 있습니다.

필요하신분은 받아가세요.

cogniti의 이미지

Quote:
그리고 Label을 TextField랑 섞어서 넣지 않으려는 이유는 ArrayList에서 따로 관리하고 싶어서 그렇습니다.

고등학교 수학책에 나와 있는 수열 공부하면
for문으로 돌려서 배치하는 문제는 단칼에 해결됩니다.
endofhope의 이미지

단지 줄만 맞추고 싶으시다면
13번째 줄을

private String [] col = {" ", "90", "80", "70", "60", "50", "40", "30", "20", "10", "0"};

로 고치시고
26번째 줄을
for (int i = 0; i <= 10; i++) 

로 바꾸면 될 듯 합니다.
결과 스크린 샷 첨부합니다.

--
말할 수 있는 것은 분명하게 말해질 수 있다;
말해질 수 없는 것에 대해서는 침묵해야한다.
논리철학논고 - 루드비히 비트겐슈타인

댓글 첨부 파일: 
첨부파일 크기
Image icon -연습.png6.74 KB

--
말할 수 있는 것은 분명하게 말해질 수 있다;
말해질 수 없는 것에 대해서는 침묵해야한다.
논리철학논고 - 루드비히 비트겐슈타인

GunSmoke의 이미지

답변 감사드립니다.

자바 처음 시작하는데 정말 큰 도움이 되고 있습니다.

大逆戰

大逆戰

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.