0

嗨,我想创建一个计费页面作为我的迷你项目的一部分,就像在图像项目计费中一样。我尝试使用 setBounds 创建它。但我没有得到想要的页面。谁能帮我做到这一点?

package start;

     void makeandshowGUI()
    {
        billno=new JTextField(15);
        dd=new JTextField(2);
        mm=new JTextField(2);
        yy=new JTextField(2);
        itemcode=new JTextField(5);
        itemname=new JTextField(50);
        qty=new JTextField(3);
        cname=new JTextField(50);
        wlcm=new JLabel("Product Billing @ BillDesk");
        ptotal=new JLabel("");
        billn=new JLabel("Bill No.:");
        billdate=new JLabel("Bill Date");
        cusname=new JLabel("Customer Name");
        pid=new JLabel("Product ID:");
         slash1=new JLabel("/");
         slash2=new JLabel("/");
        pname=new JLabel("Product Name:");
        pqty=new JLabel("Qty:");
        total=new JLabel("Total:");
        billd=new JLabel("Billing Details");
        purchased=new JLabel("Purchase Details");
        ftotal=new JLabel("Total:");
        disc=new JLabel("Discount:");
        gtotal=new JLabel("Grand Total:");
        save=new JButton("Save Bill & Print");
        view=new JButton("View Bill");
        list=new JButton("..");
        String[] columnNames = {"Sl. No.",
                                "Product ID",
                                "Product Name",
                                "Qty",
                                "Rate","Price"};


        JFrame bill=new JFrame("Product Billing || BillDesk");
        bill.setSize(1000,5000);
        bill.setBackground(Color.white);
        bill.setVisible(true);
        bill.setResizable(false);
        bill.setMinimumSize(new Dimension(1000, 1000));
        DefaultTableModel model = new DefaultTableModel(columnNames,10);
        JTable billTable=new JTable(model)
        {@Override
        public boolean isCellEditable(int arg0, int arg1) {

            return false;
        }};
        JScrollPane pane = new JScrollPane(billTable);
        Container c=bill.getContentPane();
        bill.setLayout(null);
        wlcm.setBounds(500, 0, 200, 20);
        billn.setBounds(0, 100, 100, 25);
        billno.setBounds(52,100,100,25);
        billdate.setBounds(700, 100, 100, 25);
        dd.setBounds(751, 100,20, 25);
        slash1.setBounds(772,100,5,25);
        mm.setBounds(777, 100,20, 25);
        slash2.setBounds(810,100,5,25);
        yy.setBounds(813, 100,20, 25);
        cusname.setBounds(0, 130, 50, 25);
        cname.setBounds(55, 130, 50, 25);
        pid.setBounds(0, 200, 50, 25);
        itemcode.setBounds(55, 200, 30, 25);
        pname.setBounds(100, 200, 50,25);
        itemname.setBounds(125, 200, 50,25);
        list.setBounds(206, 200, 5, 25);
        pqty.setBounds(215, 200, 25, 25);
        qty.setBounds(145, 200, 25, 25);
        total.setBounds(175, 200, 25, 25);
        ptotal.setBounds(205, 200, 50, 50); 
        c.add(wlcm,FlowLayout.LEADING);
        c.add(billn);
        c.add(billdate);
        c.add(cusname);
        c.add(pid);
        c.add(pname);
        c.add(pqty);
        c.add(slash1);
        c.add(slash2);
        c.add(ptotal);
        c.add(billno);
        c.add(dd);
        c.add(mm);
        c.add(yy);
        c.add(cname);
        c.add(cusname);
        c.add(itemcode);
        c.add(itemname);
        c.add(list);
        c.add(qty);
        c.add(total);
        c.add(ptotal);

 }
`
4

1 回答 1

1

你为什么要手动安排一切?您应该考虑使用LayoutManagerwhich 将为您处理任务。

JComponents它们的嵌套功能非常强大,可以让您创建非常整洁的 UI,而不必担心手动定位它们。每个嵌套的JComponent,比如说一个JPanel可以有一个不同的LayoutManager关联。

此外,其中的4个参数setBounds()是:

x - the new x-coordinate of this component
y - the new y-coordinate of this component
width - the new width of this component
height - the new height of this component  

问题是widthand height。手动分配它们会给您的应用程序在不同分辨率的屏幕上带来不一致的外观。ALayoutManager将为您处理所有这些。

于 2013-10-24T16:52:56.437 回答