模糊 java_为什么我的Java应用程序模糊?

这是我运行Java应用程序时显示的内容. (请参见我的按钮上的文本,文本框中的文本为java)

我在Windows 7上使用Eclipse Luna.

public class DownloadManager {

private JFrame frame;

private JTable table;

private JTextField txtUrl;

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

DownloadManager window = new DownloadManager();

window.frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

public DownloadManager() {

initialize();

}

private void initialize() {

frame = new JFrame();

frame.setBounds(100, 100, 752, 514);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane().setLayout(null);

table = new JTable();

table.setBounds(47, 190, 629, 250);

frame.getContentPane().add(table);

txtUrl = new JTextField();

txtUrl.setBounds(47, 84, 391, 34);

frame.getContentPane().add(txtUrl);

txtUrl.setColumns(10);

JButton btnDownload = new JButton("Download");

btnDownload.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

}

});

btnDownload.setBounds(534, 78, 99, 47);

frame.getContentPane().add(btnDownload);

}

}

解决方法:

使用layout manager减轻上面显示的伪像. nests下面的示例中一个JPanel另一个.

import java.awt.BorderLayout;

import java.awt.Dimension;

import java.awt.EventQueue;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.JTextField;

public class DownloadManager {

private JFrame frame;

private JTable table;

private JTextField txtUrl;

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() {

try {

DownloadManager window = new DownloadManager();

window.frame.setVisible(true);

} catch (Exception e) {

e.printStackTrace();

}

}

});

}

public DownloadManager() {

initialize();

}

private void initialize() {

frame = new JFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

table = new JTable() {

@Override

public Dimension getPreferredScrollableViewportSize() {

return new Dimension(320, 240);

}

};

frame.add(new JScrollPane(table), BorderLayout.CENTER);

txtUrl = new JTextField(12);

txtUrl.setColumns(10);

JButton btnDownload = new JButton("Download");

btnDownload.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent arg0) {

}

});

JPanel panel = new JPanel();

panel.add(txtUrl);

panel.add(btnDownload);

frame.add(panel, BorderLayout.NORTH);

frame.pack();

}

}

标签:layout,swing,jpanel,jframe,java

来源: https://codeday.me/bug/20191029/1957615.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值