Swing Не отобржается таблица - Java

Узнай цену своей работы

Формулировка задачи:

На месте белого поля должна быть таблицы
Листинг программы
  1. import javax.swing.*;
  2. import javax.swing.table.DefaultTableModel;
  3. import java.awt.print.Book;
  4. import java.io.File;
  5. /**
  6. * Created by Даниил on 14.05.2016.
  7. */
  8. public class MainFrame extends JFrame{
  9. private JButton добавить;
  10. private JButton удалить;
  11. private JButton изменить;
  12. private JButton сортировать;
  13. private JButton загрузить;
  14. private JButton сохранить;
  15. private JTextField authorField;
  16. private JTextField publisherField;
  17. private JTextField countField;
  18. private JTextField yearField;
  19. private JPanel rootPanel;
  20. private JTable BookList;
  21. private DefaultTableModel dtm;
  22. public MainFrame(){
  23. super("Lab4");
  24. setContentPane(rootPanel);
  25. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26. setVisible(true);
  27. dtm = new DefaultTableModel();
  28. dtm.setColumnIdentifiers(new String[] {"Автор","Издательство","Кол-во стр.","Год издания"});
  29. dtm.addRow(new String[] {"1","2","3","4"});
  30. BookList = new JTable(dtm);
  31. BookList.setFillsViewportHeight(true);
  32. pack();
  33. getInFileName();
  34. }
  35. File getInFileName(){
  36. JFileChooser fileopen = new JFileChooser();
  37. int ret = fileopen.showDialog(this, "Открыть файл");
  38. if (ret == JFileChooser.APPROVE_OPTION) {
  39. return fileopen.getSelectedFile();
  40. }
  41. return null;
  42. }
  43. }

Решение задачи: «Swing Не отобржается таблица»

textual
Листинг программы
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="MainFrame">
  3.   <grid id="27dc6" binding="rootPanel" layout-manager="GridBagLayout">
  4.     <constraints>
  5.       <xy x="133" y="57" width="895" height="476"/>
  6.     </constraints>
  7.     <properties>
  8.       <enabled value="true"/>
  9.     </properties>
  10.     <border type="line"/>
  11.     <children>
  12.       <component id="42fd9" class="javax.swing.JLabel">
  13.         <constraints>
  14.           <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
  15.           <gridbag top="5" left="20" bottom="5" right="60" weightx="0.0" weighty="0.0"/>
  16.         </constraints>
  17.         <properties>
  18.           <text value="Автор"/>
  19.         </properties>
  20.       </component>
  21.       <component id="fdbb" class="javax.swing.JTextField" binding="authorField">
  22.         <constraints>
  23.           <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
  24.             <preferred-size width="150" height="-1"/>
  25.           </grid>
  26.           <gridbag top="5" left="20" bottom="5" right="5" weightx="10.0" weighty="0.0"/>
  27.         </constraints>
  28.         <properties>
  29.           <text value=""/>
  30.         </properties>
  31.         <clientProperties>
  32.           <caretWidth class="java.lang.Integer" value="1"/>
  33.         </clientProperties>
  34.       </component>
  35.       <component id="d8a0e" class="javax.swing.JTextField" binding="publisherField">
  36.         <constraints>
  37.           <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
  38.             <preferred-size width="150" height="-1"/>
  39.           </grid>
  40.           <gridbag top="5" left="5" bottom="5" right="5" weightx="10.0" weighty="0.0"/>
  41.         </constraints>
  42.         <properties/>
  43.         <clientProperties>
  44.           <caretWidth class="java.lang.Integer" value="1"/>
  45.           <html.disable class="java.lang.Boolean" value="false"/>
  46.         </clientProperties>
  47.       </component>
  48.       <component id="d4a46" class="javax.swing.JTable" binding="BookList">
  49.         <constraints>
  50.           <grid row="2" column="0" row-span="3" col-span="4" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="true">
  51.             <preferred-size width="150" height="50"/>
  52.           </grid>
  53.           <gridbag top="5" left="20" bottom="5" right="20" weightx="0.5" weighty="0.5"/>
  54.         </constraints>
  55.         <properties>
  56.           <enabled value="true"/>
  57.         </properties>
  58.       </component>
  59.       <component id="c0e63" class="javax.swing.JLabel">
  60.         <constraints>
  61.           <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
  62.           <gridbag top="5" left="5" bottom="5" right="80" weightx="0.0" weighty="0.0"/>
  63.         </constraints>
  64.         <properties>
  65.           <text value="Издательство"/>
  66.         </properties>
  67.       </component>
  68.       <component id="2d266" class="javax.swing.JButton" binding="изменить">
  69.         <constraints>
  70.           <grid row="2" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
  71.           <gridbag top="10" left="10" bottom="10" right="10" weightx="0.0" weighty="0.1"/>
  72.         </constraints>
  73.         <properties>
  74.           <text value="Изменить"/>
  75.         </properties>
  76.       </component>
  77.       <component id="6216f" class="javax.swing.JButton" binding="удалить">
  78.         <constraints>
  79.           <grid row="3" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
  80.           <gridbag top="10" left="10" bottom="10" right="10" weightx="0.0" weighty="0.1"/>
  81.         </constraints>
  82.         <properties>
  83.           <text value="Удалить"/>
  84.         </properties>
  85.       </component>
  86.       <component id="b8616" class="javax.swing.JButton" binding="сортировать">
  87.         <constraints>
  88.           <grid row="4" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
  89.           <gridbag top="10" left="10" bottom="20" right="10" weightx="0.1" weighty="0.0"/>
  90.         </constraints>
  91.         <properties>
  92.           <text value="Сортировать"/>
  93.         </properties>
  94.       </component>
  95.       <component id="bfeca" class="javax.swing.JButton" binding="загрузить">
  96.         <constraints>
  97.           <grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
  98.           <gridbag top="10" left="10" bottom="20" right="70" weightx="0.1" weighty="0.0"/>
  99.         </constraints>
  100.         <properties>
  101.           <text value="Загрузить из файла"/>
  102.         </properties>
  103.       </component>
  104.       <component id="f7272" class="javax.swing.JButton" binding="сохранить">
  105.         <constraints>
  106.           <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
  107.           <gridbag top="10" left="50" bottom="20" right="10" weightx="0.1" weighty="0.0"/>
  108.         </constraints>
  109.         <properties>
  110.           <text value="Сохранить в файл"/>
  111.         </properties>
  112.       </component>
  113.       <component id="d3bca" class="javax.swing.JTextField" binding="yearField">
  114.         <constraints>
  115.           <grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
  116.             <preferred-size width="150" height="-1"/>
  117.           </grid>
  118.           <gridbag top="5" left="5" bottom="5" right="20" weightx="10.0" weighty="0.0"/>
  119.         </constraints>
  120.         <properties/>
  121.         <clientProperties>
  122.           <caretWidth class="java.lang.Integer" value="1"/>
  123.         </clientProperties>
  124.       </component>
  125.       <component id="89206" class="javax.swing.JLabel">
  126.         <constraints>
  127.           <grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
  128.           <gridbag top="5" left="5" bottom="5" right="10" weightx="0.0" weighty="0.0"/>
  129.         </constraints>
  130.         <properties>
  131.           <text value="Год издания"/>
  132.         </properties>
  133.       </component>
  134.       <component id="64de2" class="javax.swing.JLabel">
  135.         <constraints>
  136.           <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
  137.           <gridbag top="5" left="5" bottom="5" right="10" weightx="0.0" weighty="0.0"/>
  138.         </constraints>
  139.         <properties>
  140.           <text value="Кол-во стр."/>
  141.         </properties>
  142.       </component>
  143.       <component id="bd04b" class="javax.swing.JTextField" binding="countField">
  144.         <constraints>
  145.           <grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
  146.             <preferred-size width="150" height="-1"/>
  147.           </grid>
  148.           <gridbag top="5" left="5" bottom="5" right="5" weightx="10.0" weighty="0.0"/>
  149.         </constraints>
  150.         <properties/>
  151.         <clientProperties>
  152.           <caretWidth class="java.lang.Integer" value="1"/>
  153.         </clientProperties>
  154.       </component>
  155.       <component id="e6516" class="javax.swing.JButton" binding="добавить">
  156.         <constraints>
  157.           <grid row="1" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
  158.           <gridbag top="10" left="10" bottom="10" right="10" weightx="0.0" weighty="0.1"/>
  159.         </constraints>
  160.         <properties>
  161.           <text value="Добавить"/>
  162.         </properties>
  163.       </component>
  164.     </children>
  165.   </grid>
  166. </form>

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

7   голосов , оценка 4.143 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут