Java JTable不显示SQL语句的结果

Java JTable不显示SQL语句的结果,java,swing,jtable,Java,Swing,Jtable,下面是我的程序代码。 JTable未使用SQL语句的输出进行更新。 JTable未在Swing GUI上填充 import java.net.UnknownHostException; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Properties; import java.awt.

下面是我的程序代码。
JTable
未使用SQL语句的输出进行更新。
JTable
未在Swing GUI上填充

import java.net.UnknownHostException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Properties;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.ImageObserver;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;

import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.text.DefaultCaret;

public class GUIFrameExtenderImpl extends JFrame implements ActionListener {

    /**
     * 
     */
        public  static AnimatedLabel busyIcon;
        public  static JLabel busyLabelText;
        public  static Thread busyThread = null;

        public static Connection staticConnection=null;
    private static final long serialVersionUID = 1L;
    static JTable table ;

     static QueryTableModel qtm;

    public static String DATABASE_URL_CONNECTION = null;


    private static JButton executeButton = new JButton("Execute");

    private static JTextField machineName = new JTextField(50);

    static JScrollPane scrollBar = new JScrollPane(table,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    private static JTextField machineNameField = new JTextField(20);

    public static void addComponentsToPane(Container pane) {


        pane.setLayout(null);

        // Create all the labels, combo boxes, buttons, and text fields/areas
        JLabel comboAndTextLabel = new JLabel("Infra Deployer");
        JLabel driverLabel = new JLabel("Machine:");

        //JLabel SQLResultLabel = new JLabel("SQL Execution Result");

        /*JButton clearButton = new JButton("Clear Debug Table");
        JButton clearResultArea = new JButton("Clear Result Window");
        JButton executeButton = new JButton("Run Postscripts");*/

        qtm = new QueryTableModel();
         table =  new JTable(qtm);

                busyIcon=new AnimatedLabel("./images/", 100,12) ;
                busyLabelText=new JLabel("Processing...");

        pane.add(machineName);

        pane.add(comboAndTextLabel);
        pane.add(driverLabel);
        //pane.add(table);


        pane.add(machineNameField);
        pane.add(executeButton);               
                //pane.add(new JLabel("HELLOOOO")) ;
                //pane.add(busyIcon);
                //pane.add(busyLabelText);
                ////busyIcon.setVisible(false);
               // busyLabelText.setVisible(false);

        pane.add(table);
        pane.add(scrollBar);        

        machineName.setEditable(false);

        Insets insets = pane.getInsets();
        // The next giant block of code takes each component and moves them to
        // the
        // desired space on the GUI. It uses absolute positioning
        // This section moves the 5 labels on the top left
        comboAndTextLabel
                .setFont(comboAndTextLabel.getFont().deriveFont(15.0f));
        Dimension size = comboAndTextLabel.getPreferredSize();
        comboAndTextLabel.setBounds(8 + insets.left, 0 + insets.top,
                size.width, size.height + 2);
        size = driverLabel.getPreferredSize();
        driverLabel.setBounds(8 + insets.left, 26 + insets.top, size.width,
                size.height);


        // This section moves the combo boxes and the text fields on the top
        // left
        size = machineName.getPreferredSize();
        machineName.setBounds(90 + insets.left, 22 + insets.top,
                size.width - 257, size.height);




        size = machineNameField.getPreferredSize();
        machineNameField.setBounds(4440 + insets.right, 23 + insets.top,
                size.width - 1, size.height + 3);

        machineNameField.setEditable(false);


        table(8 + insets.left, 17 + insets.bottom,
                size.width + 1500, size.height + 950);

        table.setDragEnabled(false);

        // consoleOutput.setText("asdasdasfdsadfsdfsdfsdfsd");
        size = scrollBar.getPreferredSize();
        scrollBar.setBounds(8 + insets.left, 50 + insets.bottom,
                size.width + 1900, size.height + 890);

        size = executeButton.getPreferredSize();
        executeButton.setBounds(400 + insets.right, 20 + insets.top,
                size.width , size.height );

        // size = scrollingArea.getPreferredSize();
        // scrollingArea.setBounds(8 + insets.left, 217 + insets.bottom,
        // size.width + 769, size.height + 249);

        // puts border around result text area
        //
        // size = clearResultButton.getPreferredSize();
        // clearResultButton.setBounds(15 + insets.left, 820 + insets.top,
        // size.width, size.height);

        java.net.InetAddress localMachine = null;

        try {
            localMachine = java.net.InetAddress.getLocalHost();
        } catch (UnknownHostException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        machineName.setText(localMachine.getHostName());

         executeButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {                

                    //DataModify dm = new DataModify();
                    //dm.viewwindow();

                  qtm.setHostURL("jdbc:oracle:thin:@indlin2338:1521:OPTABP9");
                  qtm.setQuery("select * from ape3_epcext_offer_Details where offer_id = '8455034'");
//                //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                  System.out.println("starting" + qtm.getColumnCount());

                          }
              });





    }

        private static void table(int i, int j, int k, int l) {
        // TODO Auto-generated method stub

    }

        public static Connection getDBConnection(String driver, String url,String username,String password,boolean isDBConnected)
        {
            Connection con = null;

            if (isDBConnected==true){
                try 
                {
                    Class.forName(driver);
                    con = DriverManager.getConnection(url,username,password);                    
                }
                catch (Exception e) 
                {
                    System.out.println("Exception from getDBConnection()");
                    e.printStackTrace();
                }
            }
            return con;
        }



    // Create the GUI and show it.
    static void createAndShowGUI() {
        // Create and set up the window.
        JFrame frame = new JFrame("Infra Deployer Application 1.0");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Either using insets to shape and define size of frame.
        //Insets insets = frame.getInsets();
//      frame.setSize(1200 + insets.left + insets.right + 240, 850 + insets.top
//              + insets.bottom);

        //We are using Dimension and overriding the frame not to pack and set the size according to end user screen resolution.
         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          frame.setBounds(0,0,screenSize.width, screenSize.height);
          frame.setVisible(true);
          frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
          //frame.pack(); // Don't pack when using Dimension, pack when using insets

        frame.setResizable(false);

        // Set up the content pane.
        addComponentsToPane(frame.getContentPane());

        // Size and display the window.

        table.revalidate();
        frame.setVisible(true);

        // dispose of window when user quits application (this overrides
        // the default of HIDE_ON_CLOSE)
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

        // ensure database connection is closed when user quits application
        frame.addWindowListener(new WindowAdapter() {
            // disconnect from database and exit when window has closed
            public void windowClosed(WindowEvent event) {
                //tableModel.disconnectFromDatabase();
                System.exit(0);
            }
        });

    }



    public static void main(String[] args) {


        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub

    }


}

e1.printStackTrace()所以。。。是否有任何输出?
静态QueryTableModel qtm一个快速提示。在类成员上使用
静态
更可能导致问题,而不是解决问题。从声明的所有属性中删除每个
静态
,并了解如何在不使用静态成员的情况下执行此操作。
pane.setLayout(null)Uggh。。1) Java GUI必须在不同的操作系统、屏幕大小、屏幕分辨率等上工作,在不同的地区使用不同的PLAF。因此,它们不利于像素完美布局。而是使用布局管理器,或与布局填充和边框一起使用。2) 使用缩进代码行和代码块的逻辑和一致形式。缩进的目的是使代码的流程更易于遵循!已删除静态成员,仍然存在相同问题:(您希望我们做什么?您是否缩小了问题范围?您使用的是自定义表格模型,因此我们不知道它的功能或工作是否正常。表格是否包含数据?是否显示表格的行/列?是否将表格添加到滚动窗格?是否将滚动窗格添加到框架?选项卡的大小是多少乐。