Здравствуйте , только начинаю изучать Swing , хотел бы узнать у вас , как можно сделать так чтобы таблица и свисающее меню не отображались по центру, а были на весь экран, я понимаю , что скорее всего дело вот в этих методах
| Код | lout.columnWeights = new double[]{0.0}; lout.rowWeights = new double[]{0.0,0.0};
|
может быть даже не совсем корректно я задал вопрос , а задать его надо , как правильно переопределить констрейты
| Код | package jtable;
import java.awt.event.ActionEvent; import java.awt.*; import javax.swing.*; /** * * @author user */ public class Jtable {
public static void main(final String[] args) { JFrame mainwindow = new JFrame("Пробное окно"); mainwindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GridBagLayout lout = new GridBagLayout(); lout.columnWeights = new double[]{0.0}; lout.rowWeights = new double[]{0.0,0.0}; mainwindow.setLayout(lout); mainwindow.setLocationRelativeTo(null); String[] columnNames = { "Name", "Last modified", }; String[][] data = { {"addins", "02.11.2006 19:15", "Folder", ""}, {"AppPatch", "03.10.2006 14:10", "Folder", ""}, {"assembly", "02.11.2006 14:20", "Folder", ""}, {"Boot", "13.10.2007 10:46", "Folder", ""}, {"Branding", "13.10.2007 12:10", "Folder", ""}, {"Cursors", "23.09.2006 16:34", "Folder", ""}, {"Debug", "07.12.2006 17:45", "Folder", ""}, {"Fonts", "03.10.2006 14:08", "Folder", ""}, {"Help", "08.11.2006 18:23", "Folder", ""}, {"explorer.exe", "18.10.2006 14:13", "File", "2,93MB"}, {"helppane.exe", "22.08.2006 11:39", "File", "4,58MB"}, {"twunk.exe", "19.08.2007 10:37", "File", "1,08MB"}, {"nsreg.exe", "07.08.2007 11:14", "File", "2,10MB"}, {"explorer.exe", "18.10.2006 14:13", "File", "2,93MB"}, {"helppane.exe", "22.08.2006 11:39", "File", "4,58MB"}, {"twunk.exe", "19.08.2007 10:37", "File", "1,08MB"}, {"nsreg.exe", "07.08.2007 11:14", "File", "2,10MB"}, {"explorer.exe", "18.10.2006 14:13", "File", "2,93MB"}, }; Font font = new Font("Verdana", Font.PLAIN, 11); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.setFont(font); JMenuItem openItem = new JMenuItem("Open"); openItem.setFont(font); fileMenu.add(openItem); JMenuItem closeItem = new JMenuItem("Close"); closeItem.setFont(font); fileMenu.add(closeItem); JMenuItem closeAllItem = new JMenuItem("Close all"); closeAllItem.setFont(font); fileMenu.add(closeAllItem); fileMenu.addSeparator(); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.setFont(font); fileMenu.add(exitItem); menuBar.add(fileMenu); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.NORTH; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth=GridBagConstraints.RELATIVE; c.ipady = 0; c.gridx = 0; c.gridy = 0; c.insets = new Insets(0,0,0,0); mainwindow.add(menuBar, c); JTable table = new JTable(data, columnNames); table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); c = new GridBagConstraints(); c.anchor = GridBagConstraints.NORTH; c.ipady = 0; c.gridx = 1; c.gridy = 1; c.gridwidth=GridBagConstraints.RELATIVE; c.insets = new Insets(0,0,0,0); mainwindow.add(new JScrollPane(table), c); mainwindow.pack(); mainwindow.setVisible(true); }}
|
|