옵션 |
|
테이블을 페널에 붙이긴 했는데 테이블 목록도 안나오고 스크롤바도 안나옵니다.. 구글링 해서 똑같이도 해보고 여러 방법으로 오랜시간동안 해보았는데 뭐가 문제인지 잘 안됩니다..ㅠㅠ
테이블좀 이쁘게 붙이고 싶은데 좀 도와주실수 있으신가요..????????
파란색으로 굵게 처리한 부분이 테이블에 들어갈 데이터랑 테이블이 선언된 부분입니다.!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | package Household_Ledger; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics; import java.awt.Image; import java.awt.TextField; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Hashtable; import java.util.StringTokenizer; import javax.imageio.ImageIO; import javax.swing.DefaultComboBoxModel; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JLayeredPane; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.ScrollPaneConstants; import javax.swing.table.DefaultTableModel; import javax.swing.table.JTableHeader; public class HL_main extends JFrame implements ActionListener{ BufferedImage img = null; JButton back, insert, sort; JLabel date, expectation, category, lb_EI, Cc, memo, price,lb_EXPECT; TextField txt_date, txt_memo, txt_price; JComboBox<String> cmbBox, cmbBox2,expenseIncome,cashCredit; Hashtable<String, String[]> subItems = new Hashtable<String, String[]>(); Member[] info = new Member[1000]; int counter = 0, EXPECT = 0, month = 0,month_tmp = 0; public static int [] earnTotal = new int[12];//월 public static int [] expenseTotal = new int[12]; public static int [][] cateEarnSum = new int[13][12];//카테고리, 월 public static int [][] cateExpenseSum = new int[13][12]; String[] strCateCombo = new String[2]; String[] strExpenseCash = new String[2]; String strGetDate, strGetMemo, strGetPrice; String[] cate01 = new String[] {"Choose","식비", "주거/통신", "생활용품", "의복/미용", "건강/문화", "교육/육아", "교통/차량", "경조사/회비", "세금/이자", "월급/기타", "카드대금","저축보험","미분류" }; String[] cate_00 = {"Choose","주식", "부식", "간식", "외식", "커피/음료", "술/유흥", "기타"}; String[] cate_01 = new String[] {"Choose","관리비", "공과금", "이동통신", "인터넷", "월세", "기타"}; String[] cate_02 = new String[] {"Choose","가구/가전", "주방/욕실", "잡화/소모", "기타"}; String[] cate_03 = new String[] {"Choose","의류비", "패션/잡화", "헤어뷰티", "세탁수선비","기타"}; String[] cate_04 = new String[] {"Choose","운동/레저", "문화생활", "여행", "병원비", "기타", "보장성보험"}; String[] cate_05 = new String[] {"Choose","등록금", "학원교재비", "육아용품", "기타"}; String[] cate_06 = new String[] {"Choose","대중교통비", "주유비", "자동차보험","기타"}; String[] cate_07 = new String[] {"Choose","경조사비", "모임회비", "데이트", "선물","기타"}; String[] cate_08 = new String[] {"Choose","세금", "대출이자","기타"}; String[] cate_09 = new String[] {"Choose","월급","용돈","기타"}; String[] cate_10 = new String[] {"Choose","카드대금"}; String[] cate_11 = new String[] {"Choose","예금", "적금", "펀드", "보험", "투자", "기타"}; String[] cate_12 = new String[] {"미분류"}; String[] EI = new String[] {"Choose","지출","수입"}; String[] str_Cc = new String[] {"Choose","카드","현금"}; HL_main() throws IOException{ fileRead read = new fileRead(); EXPECT = HouseholdLedger.EXPECTATION; System.out.println("예산 : "+EXPECT); setTitle("Household Ledger Main"); setSize(1280,720); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Dimension frameSize = this.getSize(); Dimension windowSize = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((windowSize.width - frameSize.width)/2,(windowSize.height - frameSize.height)/2); JLayeredPane layeredPan = new JLayeredPane(); layeredPan.setBounds(0,0,1280,720); layeredPan.setLayout(null); try { img = ImageIO.read(new File("C:/Users/aolo26698824/workspace/JAVA/src/image/mainBac.jpg")); } catch (Exception e) { System.out.println("Load Error"); System.exit(0); } JPanel pn = new MyPanel(); pn.setBounds(0,0,1280,720); back = new JButton(new ImageIcon("C:/Users/aolo26698824/workspace/JAVA/src/image/back.png")); back.setBounds(5, 5, 50, 40); back.addActionListener(this); back.setBorderPainted(false); back.setFocusPainted(false); back.setContentAreaFilled(false); //FONT Font LB_font = new Font("맑은 고딕",Font.BOLD,24); Font LB_font2 = new Font("맑은 고딕",Font.BOLD,22); Font LB_font3 = new Font("맑은 고딕",Font.BOLD,28); Font TX_font = new Font("맑은 고딕",Font.BOLD,20); Font TX_font2 = new Font("맑은 고딕",Font.BOLD,16); Font TX_price = new Font("맑은 고딕",Font.BOLD,28); date = new JLabel("날 짜"); date.setFont(LB_font); date.setBounds(40, 70, 110, 60); //date TextField txt_date = new TextField(8); txt_date.setFont(TX_font); txt_date.setBounds(180,90,110,30); expectation = new JLabel("예산액"); expectation.setFont(LB_font); expectation.setBounds(360,70,110,60); //i should add expectation Lable. lb_EXPECT = new JLabel(EXPECT+"원"); lb_EXPECT.setFont(LB_font3); lb_EXPECT.setBounds(460, 72, 140, 60); category = new JLabel("카테고리"); category.setFont(LB_font); category.setBounds(40,140,110,60); cmbBox2 = new JComboBox<String>(); cmbBox2.setPrototypeDisplayValue("XXXXX"); subItems.put(cate01[1],cate_00); subItems.put(cate01[2],cate_01); subItems.put(cate01[3],cate_02); subItems.put(cate01[4],cate_03); subItems.put(cate01[5],cate_04); subItems.put(cate01[6],cate_05); subItems.put(cate01[7],cate_06); subItems.put(cate01[8],cate_07); subItems.put(cate01[9],cate_08); subItems.put(cate01[10],cate_09); subItems.put(cate01[11],cate_10); subItems.put(cate01[12],cate_11); subItems.put(cate01[13],cate_12); cmbBox2.setFont(TX_font2); cmbBox2.setBounds(360,160,140,30); //define multiple combobox cmbBox = new JComboBox<String>(cate01); cmbBox.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { String item = (String)cmbBox.getSelectedItem(); Object o = subItems.get(item); if(o == null){ cmbBox2.setModel(new DefaultComboBoxModel<String>()); } else{ cmbBox2.setModel(new DefaultComboBoxModel<String>((String[])o)); } } }); cmbBox.setBounds(180,160,140,30); //store selected string cmbBox.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { strCateCombo[0] = (String) cmbBox.getSelectedItem(); } }); cmbBox2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { strCateCombo[1] = (String) cmbBox2.getSelectedItem(); } }); lb_EI = new JLabel("수입/지출"); lb_EI.setFont(LB_font2); lb_EI.setBounds(40,225,140,30); expenseIncome = new JComboBox<String>(EI); expenseIncome.setFont(TX_font2); expenseIncome.setBounds(180,225,140,30); Cc = new JLabel("현금/카드"); Cc.setFont(LB_font2); Cc.setBounds(360,225,140,30); cashCredit = new JComboBox<String>(str_Cc); cashCredit.setFont(TX_font2); cashCredit.setBounds(500,225,140,30); expenseIncome.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { strExpenseCash[0] = (String)expenseIncome.getSelectedItem(); } }); cashCredit.addActionListener(new ActionListener (){ public void actionPerformed(ActionEvent e) { strExpenseCash[1] = (String)cashCredit.getSelectedItem(); } }); memo = new JLabel("MEMO"); memo.setFont(LB_font); memo.setBounds(40,290,140,30); txt_memo = new TextField(200); txt_memo.setFont(TX_font2); txt_memo.setBounds(180,290,460,30); price = new JLabel("가 격"); price.setFont(LB_font); price.setBounds(670,290,140,30); txt_price = new TextField(8); txt_price.setFont(TX_price); txt_price.setBounds(740,290,190,30); //시계 이미지 ImgClock imgClock = new ImgClock(); imgClock.setLayout(null); imgClock.setBounds(1050,100,200,200); imgClock.setOpaque(false); new Thread(imgClock).start(); //시계 ClockMessage clockMessage = new ClockMessage(); clockMessage.setBounds(1050,30,220,60); clockMessage.setOpaque(false); new Thread(clockMessage).start(); insert = new JButton(new ImageIcon("C:/Users/aolo26698824/workspace/JAVA/src/image/btn_insert.png")); insert.setBounds(960,277,80,50); insert.addActionListener(this); insert.setBorderPainted(false); insert.setFocusPainted(false); insert.setContentAreaFilled(false); sort = new JButton(new ImageIcon("C:/Users/aolo26698824/workspace/JAVA/src/image/btn_sort.png")); sort.setBounds(1100,280,80,50); sort.addActionListener(this); sort.setBorderPainted(false); sort.setFocusPainted(false); sort.setContentAreaFilled(false); Object rowData[][] = new Object[counter][7]; for(int i = 0; i < counter; i++){ for(int j = 0; j < 7; j++) switch(j){ case 0: rowData[i][j] = String.valueOf(info[i].date); break; case 1: rowData[i][j] = info[i].cmb_01; break; case 2: rowData[i][j] = info[i].cmb_02; break; case 3: rowData[i][j] = info[i].cmb_03; break; case 4: rowData[i][j] = info[i].cmb_04; break; case 5: rowData[i][j] = info[i].txtBox; break; case 6: rowData[i][j] = String.valueOf(info[i].price); break; } } //테이블!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! String[] columnNames = {"날짜", "카테고리01", "카테고리02", "수입/지출", "카드/현금", "메모", "금액"}; JTable table = new JTable(rowData,columnNames); table.setBounds(40, 350, 1100, 250); //table.setFillsViewportHeight(true); JScrollPane js = new JScrollPane(table); js.setVisible(true); //adddd layeredPan.add(table); layeredPan.add(lb_EXPECT); layeredPan.add(txt_price); layeredPan.add(price); layeredPan.add(sort); layeredPan.add(insert); layeredPan.add(clockMessage); layeredPan.add(imgClock); layeredPan.add(txt_memo); layeredPan.add(memo); layeredPan.add(cashCredit); layeredPan.add(Cc); layeredPan.add(expenseIncome); layeredPan.add(lb_EI); layeredPan.add(cmbBox2); layeredPan.add(cmbBox); layeredPan.add(category); layeredPan.add(expectation); layeredPan.add(txt_date); layeredPan.add(date); layeredPan.add(back); layeredPan.add(pn); add(layeredPan); setVisible(true); } public static void main(String[] args) throws IOException { // TODO Auto-generated method stub HL_main main = new HL_main(); } class MyPanel extends JPanel{ public void paint(Graphics g){ g.drawImage(img, 0, 0, null); } } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getSource() == back){ setVisible(false); // 현재 프레임을 안보이게함 dispose(); // 현재 프레임을 제거 HouseholdLedger HL= new HouseholdLedger(); HL.setVisible(true); }else if(e.getSource() == insert){ strGetDate = txt_date.getText(); strGetMemo = txt_memo.getText(); strGetPrice = txt_price.getText(); info[counter] = new Member(); info[counter].date = Integer.parseInt(strGetDate); info[counter].cmb_01 = strCateCombo[0]; info[counter].cmb_02 = strCateCombo[1]; info[counter].cmb_03 = strExpenseCash[0]; info[counter].cmb_04 = strExpenseCash[1]; info[counter].txtBox = strGetMemo; info[counter].price = Integer.parseInt(strGetPrice); month = info[counter].date % 10000; month_tmp = month % 100; month -= month_tmp; month = month / 100; month -= 1; //수입인지 지출인지 확인후 더해 if(info[counter].cmb_03.equals("수입")){ earnTotal[month] += info[counter].price; }else if(info[counter].cmb_03.equals("지출")){ expenseTotal[month] += info[counter].price; } //카테고리 총 합 더해줌 for(int q = 0; q < 13; q++) if(info[counter].cmb_01.equals(cate01[q+1])) if(info[counter].cmb_03.equals("수입")){ cateEarnSum[q][month] += info[counter].price; }else if(info[counter].cmb_03.equals("지출")){ cateExpenseSum[q][month] += info[counter].price; } Object rowData[][] = new Object[counter][7]; System.out.println((month+1)+" earn! : "+earnTotal[month]+" expendse : "+expenseTotal[month]); try { fileWrite write = new fileWrite(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JOptionPane.showMessageDialog(null,"Added!"); counter++; }else if(e.getSource() == sort){} } class ImgClock extends JPanel implements Runnable{ /** * */ private static final long serialVersionUID = 1L; Image img[] = new Image[7]; int i = 2; public ImgClock(){ img[1] = Toolkit.getDefaultToolkit().createImage("C:/Users/aolo26698824/workspace/JAVA/src/image/시계(1).png"); img[2] = Toolkit.getDefaultToolkit().createImage("C:/Users/aolo26698824/workspace/JAVA/src/image/시계(2).png"); img[3] = Toolkit.getDefaultToolkit().createImage("C:/Users/aolo26698824/workspace/JAVA/src/image/시계(3).png"); img[4] = Toolkit.getDefaultToolkit().createImage("C:/Users/aolo26698824/workspace/JAVA/src/image/시계(4).png"); img[5] = Toolkit.getDefaultToolkit().createImage("C:/Users/aolo26698824/workspace/JAVA/src/image/시계(5).png"); img[6] = Toolkit.getDefaultToolkit().createImage("C:/Users/aolo26698824/workspace/JAVA/src/image/시계(6).png"); img[0] = img[1]; } public void paint(Graphics g){ super.paint(g); g.drawImage(img[0], 0, 0, this); } public void run() { while(true){ try{ Thread.sleep(10000); switch(i){ case 1: img[0] = img[i]; i++; repaint(); break; case 2: img[0] = img[i]; i++; repaint(); break; case 3: img[0] = img[i]; i++; repaint(); break; case 4: img[0] = img[i]; i++; repaint(); break; case 5: img[0] = img[i]; i++; repaint(); break; case 6: img[0] = img[i]; i=1; repaint(); break; } } catch(InterruptedException e){ e.printStackTrace(); } } } } class ClockMessage extends JPanel implements Runnable{ int i = Calendar.getInstance().get(Calendar.AM_PM); String[] amPm = {"AM", "PM"}; SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss"); String time = sdf.format(new Date()); JLabel timeLabel, ampmLabel; public ClockMessage(){ this.setLayout(null); timeLabel = new JLabel(time); timeLabel.setBounds(80,26,150,30); timeLabel.setForeground(Color.BLACK); timeLabel.setFont(new Font("맑은 고딕",Font.BOLD,28)); ampmLabel = new JLabel(amPm[i]); ampmLabel.setBounds(0,0,90,60); ampmLabel.setForeground(Color.BLACK); ampmLabel.setFont(new Font("맑은 고딕",Font.BOLD,50)); add(timeLabel,BorderLayout.NORTH); add(ampmLabel,BorderLayout.CENTER); } public void run() { do{ try{ Thread.sleep(1000); }catch(InterruptedException e){ e.printStackTrace(); } timeLabel.setText(sdf.format(new Date())); }while(true); } } class fileRead{ fileRead() throws IOException{ String[] tmp = new String[8]; int i = 0; StringTokenizer token; try{ File aFile = new File("C:/Users/aolo26698824/workspace/JAVA/src/HsLedger.txt"); FileReader fileReader = new FileReader(aFile); BufferedReader reader = new BufferedReader(fileReader); String line = null; while((line = reader.readLine()) != null){ token = new StringTokenizer(line," \n"); while(token.hasMoreTokens()){ tmp[i++] = token.nextToken(); } info[counter] = new Member(); info[counter].date = Integer.parseInt(tmp[0]); info[counter].cmb_01 = tmp[1]; info[counter].cmb_02 = tmp[2]; info[counter].cmb_03 = tmp[3]; info[counter].cmb_04 = tmp[4]; info[counter].txtBox = tmp[5]; info[counter].price = Integer.parseInt(tmp[6]); //달 계산 month = info[counter].date % 10000; month_tmp = month % 100; month -= month_tmp; month = month / 100; month -= 1; System.out.println(month+1); //항목별 합계 for(int q = 0; q < 13; q++) if(info[counter].cmb_01.equals(cate01[q+1])) if(info[counter].cmb_03.equals("수입")){ cateEarnSum[q][month] += info[counter].price; }else if(info[counter].cmb_03.equals("지출")){ cateExpenseSum[q][month] += info[counter].price; } //달별 수입. 지출 if(info[counter].cmb_03.equals("수입")){ earnTotal[month] += info[counter].price; }else if(info[counter].cmb_03.equals("지출")){ expenseTotal[month] += info[counter].price; } System.out.println("counter : "+counter+ " "+info[counter].date+" "+info[counter].cmb_01+" "+info[counter].cmb_02+" "+info[counter].cmb_03+" "+info[counter].cmb_04+" "+info[counter].txtBox+" "+info[counter].price); counter++; i = 0; } System.out.println("earn! : "+earnTotal[9]+" expendse : "+expenseTotal[9]); for(int q = 0; q < 13; q++) System.out.println(cate01[q+1] + " 수입 : " + cateEarnSum[q][9]+ " 지출 : " +cateExpenseSum[q][9]); reader.close(); fileReader.close(); }catch(Exception ex){ } } } class fileWrite{ fileWrite() throws IOException{ try{ BufferedWriter fw; fw = new BufferedWriter(new FileWriter("C:/Users/aolo26698824/workspace/JAVA/src/HsLedger.txt",true)); fw.write(strGetDate+" "+strCateCombo[0]+" "+strCateCombo[1]+" "+strExpenseCash[0]+" "+strExpenseCash[1]+" "+strGetMemo+" "+strGetPrice+"\n"); fw.close(); }catch(Exception ex){ ex.printStackTrace(); } } } } class Member{ int date; String cmb_01; String cmb_02; String cmb_03; String cmb_04; String txtBox; int price; } | cs |
조공짤....ㅎㅎ