swing JTable 의 셀을 합치는...

sellee의 이미지

테이블헤더가 html의 rowspan, colspan같이 합해서 보여지는
jtable을 아시는지요.

아시면 제발 도와주세요. 클났읍니다...

http://www.senun.com/Left/Programming/Java_old/Examples_swing/JTableExamples1.html
에서 나오는
jp.gr.java_conf.tame.*가 있는것같지만..
jdk1.2까지만 실행이 되더군요. ㅜㅜ;

futari의 이미지

글쎄요.. 돌려보니 약간 point 처리에 문제가 있을 뿐이지 1.4에서 돌아가는데 무리가 없습니다.

HeaderRenderer의 값이 default로 null이라는 것만 감안해서 그 부분을 처리후 사용하시면 저기 있는 소스들은 point 처리만 손본 후에 그냥 copy&paste로 사용하셔도 될 정도네요.

** 몇몇가지는 신기한 짓도 하는군요. 나중에 살펴봐야겠습니다 ㅎㅎㅎ

-------------------------
The universe is run by the complex interweaving of three elements: matter, energy, and enlightened self-interest.
- G'kar, Babylon 5

익명 사용자의 이미지

GroupableHeaderExample.java 를 바꾸어주면 어째뜬 실행은 됍니다

http://java-house.jp/ml/archive/j-h-b/045019.html

에서 찾았고요.

근데...
선이 안나오고 배경도 이상하고..
도와주세요...

TableColumnModel cm = table.getColumnModel();
// line 42// ここから追加
for (int idx = 0;idx < cm.getColumnCount(); idx++) {
cm.getColumn(idx).setHeaderRenderer(new
DefaultTableCellRenderer()
);
}
// ここまで

bejoy4him의 이미지

구글에서 찾아보니 다음과 같은 글이 있었습니다.
말씀하신 대로 1.3버전부터는 그대로 사용할수 없고 수정이 가해져야 한다는 군요..

인용한 부분의 마지막에 나타난 썬의 포럼 링크를 따라가 보면....
그에 대한 게시글과 예제 코드들도 나와있는듯 합니다.

픽스된 코드는 게시물 쭈욱 아래쪽에 나와있는듯 합니다. ^^

아..참고로 인용한 게시물의 링크는 다음과 같습니다.
http://www.jguru.com/faq/view.jsp?EID=12652

위 게시물의 가장 마지막 답글입니다.

문제는 제가 글을 끝까지 읽어보지 않아서 위와 중복되는 내용인지는 잘 모르겠습니다. 그냥 쭈욱 훌터보니 그 해결 코드가 있는듯 해서요... ^^ 넘 무책임한가?

Quote:
How can I make a column header of a JTable span over two columns?
Jerry Lampi, Feb 20, 2004

Here is some useful information for this post.

The new link to these valuble Swing examples is: http://www.senun.com/Left/Programming/Java_old/Examples_swing/SwingExamples.html

In Java 1.3 and above, the code will not work as shown in the samples. You must change how the TableCellRenderer is gotten in two methods. The paintCell() and getHeaderHeight() methods of the GroupableTableHeaderUI class as follows:

// Comment out old way of doing it:
// TableCellRenderer renderer = aColumn.getHeaderRenderer();
// Add this line to get it the new way:
TableCellRenderer renderer = header.getTable().getTableHeader().getDefaultRenderer();

Here's the link that prescibes fixes to bring it up to 1.3 SDK:

http://forum.java.sun.com/thread.jsp?thread=126564&forum=57&message=334998

익명 사용자의 이미지

해결하였읍니다.
감사합니다.
swing개발장에게 유익한 정보가 되리라 생각됩니다.

한가지... 선이 한군데만 하얀건.. 어쩔수 없나...

익명 사용자의 이미지

line 53 edit
//cellRect.width = aColumn.getWidth() + columnMargin; // here
cellRect.width = aColumn.getWidth();

line 66,89 add
if(renderer==null) renderer = getNewRenderer(); // here
if(renderer==null) renderer = getNewRenderer(); // here

append method
private TableCellRenderer getNewRenderer(){
return header.getDefaultRenderer();
}

익명 사용자의 이미지

GroupableTableHeader .60
cGroup.setColumnMargin(columnMargin);
->
cGroup.setColumnMargin(columnMargin-1);

cronex의 이미지

돌아가는 소스가 있는 곳.

http://www.swebb99.f2s.com/GroupableHeader/

------------------------------------------------------------
이 멍청이~! 나한테 이길 수 있다고 생각했었냐~?
광란의 귀공자 데코스 와이즈멜 님이라구~!

------------------------------------------------------------
이 멍청이~! 나한테 이길 수 있다고 생각했었냐~?
광란의 귀공자 데코스 와이즈멜 님이라구~!

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.