3

This is what I wish to make
what i want to make

This is what is being showed when I run my java application. (see the text on my button and the text in text box is java) what is it being made

I am using Eclipse Luna on Windows 7.

PS: My labels are blurry in Java was not of any help

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);
    }
}

EDIT:
Solution suggested by Swing rendering appears broken in JDK 1.8, correct in JDK 1.7 i.e. changing the energy control settings of NVIDIA GeForce 630M to maximum performance did not help.

Community
  • 1
  • 1
hoder
  • 257
  • 1
  • 3
  • 14
  • 1
    And you think two photos is all the information we need to solve your issue? – Lrrr Sep 21 '14 at 12:03
  • @AliAmiri I added the whole code of class – hoder Sep 21 '14 at 12:05
  • 1
    Hello, you can find an answer here: http://stackoverflow.com/questions/22737535/swing-rendering-appears-broken-in-jdk-1-8-correct-in-jdk-1-7/26610279#26610279 – duffy356 Oct 28 '14 at 19:02

1 Answers1

4

Use a layout manager to mitigate the artifacts shown above. The example below nests one JPanel in another.

enter image description here

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();
    }
}
Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045