Swing Не отобржается таблица - Java
Формулировка задачи:
На месте белого поля должна быть таблицы
import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.print.Book; import java.io.File; /** * Created by Даниил on 14.05.2016. */ public class MainFrame extends JFrame{ private JButton добавить; private JButton удалить; private JButton изменить; private JButton сортировать; private JButton загрузить; private JButton сохранить; private JTextField authorField; private JTextField publisherField; private JTextField countField; private JTextField yearField; private JPanel rootPanel; private JTable BookList; private DefaultTableModel dtm; public MainFrame(){ super("Lab4"); setContentPane(rootPanel); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); dtm = new DefaultTableModel(); dtm.setColumnIdentifiers(new String[] {"Автор","Издательство","Кол-во стр.","Год издания"}); dtm.addRow(new String[] {"1","2","3","4"}); BookList = new JTable(dtm); BookList.setFillsViewportHeight(true); pack(); getInFileName(); } File getInFileName(){ JFileChooser fileopen = new JFileChooser(); int ret = fileopen.showDialog(this, "Открыть файл"); if (ret == JFileChooser.APPROVE_OPTION) { return fileopen.getSelectedFile(); } return null; } }
Решение задачи: «Swing Не отобржается таблица»
textual
Листинг программы
<?xml version="1.0" encoding="UTF-8"?> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="MainFrame"> <grid id="27dc6" binding="rootPanel" layout-manager="GridBagLayout"> <constraints> <xy x="133" y="57" width="895" height="476"/> </constraints> <properties> <enabled value="true"/> </properties> <border type="line"/> <children> <component id="42fd9" class="javax.swing.JLabel"> <constraints> <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"/> <gridbag top="5" left="20" bottom="5" right="60" weightx="0.0" weighty="0.0"/> </constraints> <properties> <text value="Автор"/> </properties> </component> <component id="fdbb" class="javax.swing.JTextField" binding="authorField"> <constraints> <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"> <preferred-size width="150" height="-1"/> </grid> <gridbag top="5" left="20" bottom="5" right="5" weightx="10.0" weighty="0.0"/> </constraints> <properties> <text value=""/> </properties> <clientProperties> <caretWidth class="java.lang.Integer" value="1"/> </clientProperties> </component> <component id="d8a0e" class="javax.swing.JTextField" binding="publisherField"> <constraints> <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"> <preferred-size width="150" height="-1"/> </grid> <gridbag top="5" left="5" bottom="5" right="5" weightx="10.0" weighty="0.0"/> </constraints> <properties/> <clientProperties> <caretWidth class="java.lang.Integer" value="1"/> <html.disable class="java.lang.Boolean" value="false"/> </clientProperties> </component> <component id="d4a46" class="javax.swing.JTable" binding="BookList"> <constraints> <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"> <preferred-size width="150" height="50"/> </grid> <gridbag top="5" left="20" bottom="5" right="20" weightx="0.5" weighty="0.5"/> </constraints> <properties> <enabled value="true"/> </properties> </component> <component id="c0e63" class="javax.swing.JLabel"> <constraints> <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"/> <gridbag top="5" left="5" bottom="5" right="80" weightx="0.0" weighty="0.0"/> </constraints> <properties> <text value="Издательство"/> </properties> </component> <component id="2d266" class="javax.swing.JButton" binding="изменить"> <constraints> <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"/> <gridbag top="10" left="10" bottom="10" right="10" weightx="0.0" weighty="0.1"/> </constraints> <properties> <text value="Изменить"/> </properties> </component> <component id="6216f" class="javax.swing.JButton" binding="удалить"> <constraints> <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"/> <gridbag top="10" left="10" bottom="10" right="10" weightx="0.0" weighty="0.1"/> </constraints> <properties> <text value="Удалить"/> </properties> </component> <component id="b8616" class="javax.swing.JButton" binding="сортировать"> <constraints> <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"/> <gridbag top="10" left="10" bottom="20" right="10" weightx="0.1" weighty="0.0"/> </constraints> <properties> <text value="Сортировать"/> </properties> </component> <component id="bfeca" class="javax.swing.JButton" binding="загрузить"> <constraints> <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"/> <gridbag top="10" left="10" bottom="20" right="70" weightx="0.1" weighty="0.0"/> </constraints> <properties> <text value="Загрузить из файла"/> </properties> </component> <component id="f7272" class="javax.swing.JButton" binding="сохранить"> <constraints> <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"/> <gridbag top="10" left="50" bottom="20" right="10" weightx="0.1" weighty="0.0"/> </constraints> <properties> <text value="Сохранить в файл"/> </properties> </component> <component id="d3bca" class="javax.swing.JTextField" binding="yearField"> <constraints> <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"> <preferred-size width="150" height="-1"/> </grid> <gridbag top="5" left="5" bottom="5" right="20" weightx="10.0" weighty="0.0"/> </constraints> <properties/> <clientProperties> <caretWidth class="java.lang.Integer" value="1"/> </clientProperties> </component> <component id="89206" class="javax.swing.JLabel"> <constraints> <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"/> <gridbag top="5" left="5" bottom="5" right="10" weightx="0.0" weighty="0.0"/> </constraints> <properties> <text value="Год издания"/> </properties> </component> <component id="64de2" class="javax.swing.JLabel"> <constraints> <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"/> <gridbag top="5" left="5" bottom="5" right="10" weightx="0.0" weighty="0.0"/> </constraints> <properties> <text value="Кол-во стр."/> </properties> </component> <component id="bd04b" class="javax.swing.JTextField" binding="countField"> <constraints> <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"> <preferred-size width="150" height="-1"/> </grid> <gridbag top="5" left="5" bottom="5" right="5" weightx="10.0" weighty="0.0"/> </constraints> <properties/> <clientProperties> <caretWidth class="java.lang.Integer" value="1"/> </clientProperties> </component> <component id="e6516" class="javax.swing.JButton" binding="добавить"> <constraints> <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"/> <gridbag top="10" left="10" bottom="10" right="10" weightx="0.0" weighty="0.1"/> </constraints> <properties> <text value="Добавить"/> </properties> </component> </children> </grid> </form>
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д