Prześwitujący problem w Swingu.

0

Witam, zdaję sobie sprawę że Swing jest nieużywany, ale akurat mi jest potrzebny w taki, a nie inny sposób.
Otóż mam problem z formatką którą zrobiłem, a mianowicie jak najadę kursorem na button textfield lub inny reagujące pole to tam pokazują mi się jakieś literki obrazki jakby coś przebijało nie wiem skąd to się bierze i jak temu zaradzić.


import java.awt.*;
import javax.swing.*;

public class Register extends JFrame {
	
	/**
	 * 
	 */
	
	/**
	 * 
	 */
	Toolkit kit = Toolkit.getDefaultToolkit();
	Dimension screenSize = kit.getScreenSize();
	int screenWidth = screenSize.width;
	int screenHeight = screenSize.height;
	
	
	private JLabel lBackground, lFryz, lLoginIcon, lPasswordIcon;
	private JPanel pLogin, pHeader;
	private JPasswordField passwordField;
	private JTextField tfUser;
	private JButton bSingIn, bSingUp, bWithoutLog, bClose, bMinimize;
	private JSeparator userSeparator, passwordSeparator;
	
	public ImageIcon icon(String source,int sizeX,int sizeY) {
		
		ImageIcon backgroundImage = new ImageIcon(source);
		Image img = backgroundImage.getImage().getScaledInstance(sizeX,sizeY,Image.SCALE_SMOOTH);
		
		return backgroundImage = new ImageIcon(img);
	}
	
	public int eWidth(int a) {
		double x = screenWidth/3/a;
		int y = (int)(screenWidth/3/x);
		
		return y;
	}
	
	public int eHeight(int a) {
		double x = screenHeight/3/a;
		int y = (int)(screenHeight/3/x);
		
		return y;
	}

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Register frame = new Register();
//					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */

	public Register() {
		
		
		//frame
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLayout(null);
		setSize(screenWidth/3,screenHeight/2);
		setLocationRelativeTo(null);
		setUndecorated(true);
		setVisible(true);
		
		//background
		
		lBackground = new JLabel("", icon("D:\\wlosy.jpg",screenWidth/3,screenHeight/2), JLabel.CENTER);
		lBackground.setBounds(0,0,screenWidth/3,screenHeight/2);
		add(lBackground);
		
		//login panel
		pLogin = new JPanel();
		pLogin.setBounds(50, 125, 355, 210);
		pLogin.setBackground(new Color(0,0,0,80));
		pLogin.setLayout(null);
		lBackground.add(pLogin);
	
		lLoginIcon = new JLabel("", icon("D:\\maleUsers.png",20,20),JLabel.CENTER);
		lLoginIcon.setBounds(100, 50, 20, 20);
		pLogin.add(lLoginIcon);
		
		lPasswordIcon = new JLabel("",icon("D:\\passwordKey.png",20,20),JLabel.CENTER);
		lPasswordIcon.setBounds(100, 100, 20, 20);
		pLogin.add(lPasswordIcon);
		
		passwordField = new JPasswordField();
//		passwordField.setText("hasło");
		passwordField.setForeground(new Color(255, 255, 255));
		passwordField.setBackground(new Color(0,0,0,0));
		passwordField.setBounds(130, 100, 150, 20);
		//passwordField.setBorder(null);
		pLogin.add(passwordField);
		
		tfUser = new JTextField("");
//		tfUser.setText("nazwa u\u017Cytkownika");
		tfUser.setBackground(new Color(0,0,0,0));
		tfUser.setForeground(new Color(255, 255, 255));
		tfUser.setBounds(130, 50, 150, 20);
		tfUser.setBorder(null);
		pLogin.add(tfUser);
//		tfUser.setColumns(10);
		
		bSingUp = new JButton("Zaloguj");
		bSingUp.setForeground(new Color(255, 255, 255));
		bSingUp.setFont(new Font("Segoe UI Black", Font.PLAIN, 11));
		bSingUp.setBackground(new Color(0,0,0,75));
		bSingUp.setBorder(null);
//		bSingUp.setOpaque(false);
		bSingUp.setBounds(191, 131, 89, 23);
		pLogin.add(bSingUp);
		
		bSingIn = new JButton("Nie masz konta? Za\u0142\u00F3\u017C!");
		bSingIn.setFont(new Font("Segoe UI Black", Font.PLAIN, 11));
		bSingIn.setBackground(new Color(0,0,0,75));
		bSingIn.setBorder(null);
		bSingIn.setBounds(10, 176, 159, 23);
		pLogin.add(bSingIn);
		
		bWithoutLog = new JButton("Kontynuuj bez logowania");
		bWithoutLog.setFont(new Font("Segoe UI Black", Font.PLAIN, 11));
		bWithoutLog.setBackground(new Color(0,0,0,75));
		bWithoutLog.setBorder(null);
		bWithoutLog.setBounds(180, 176, 159, 23);
		pLogin.add(bWithoutLog);
		
		userSeparator = new JSeparator();
		userSeparator.setBounds(130, 70, 150, 3);
		pLogin.add(userSeparator);
		
		passwordSeparator = new JSeparator();
		passwordSeparator.setBounds(130, 120, 150, 3);
		pLogin.add(passwordSeparator);
		
		//header
		pHeader = new JPanel();
		pHeader.setForeground(new Color(102, 0, 0));
		pHeader.setBounds(0, 0, 455, 50);
	//	pHeader.setBackground(new Color(0,0,0,50));
		pHeader.setLayout(null);
		lBackground.add(pHeader);
		
		lFryz = new JLabel("Fryz");
		lFryz.setFont(new Font("Trajan Pro", Font.BOLD | Font.ITALIC, 25));
		lFryz.setHorizontalAlignment(SwingConstants.CENTER);
		lFryz.setForeground(new Color(102, 0, 0));
		lFryz.setBounds(184, 11, 93, 42);
		pHeader.add(lFryz);
		
		bClose = new JButton();
		bClose.setIcon(icon("D:\\cross.png",20,20));
		bClose.setBackground(new Color(0,0,0,0));
		bClose.setBorder(null);
		bClose.setBounds(435, 1, 20, 20);
		pHeader.add(bClose);
		
		bMinimize = new JButton();
		bMinimize.setIcon(icon("D:\\line.png",20,20));
		bMinimize.setBackground(new Color(0,0,0,0));
		bMinimize.setBorder(null);
		bMinimize.setBounds(413, 1, 20, 20);
		pHeader.add(bMinimize);
	
	}
}

0
  1. Daj tam gdzieś na koniec pack()
  2. Takie rzeczy jak setVisible(true); to daj może jak już wszystkie komenty dodasz.
0
Shalom napisał(a):
  1. Daj tam gdzieś na koniec pack()
  2. Takie rzeczy jak setVisible(true); to daj może jak już wszystkie komenty dodasz.

No tak tylko w dalszym ciągu nie rozwiązuje to mojego problemu po dodaniu metody pack() wgl nie wyświetla mi żadnej ramki

0

no tak tylko z tego co czytam to, albo pack() albo setSize pack służy do automatycznego ustawienia rozmiaru okna tak żeby zmieściły się w nim wszystkie komponenty. Mieszczą się one bo widze to w design. No i wraz to pack() do niczego mi nie jest potrzebne aktualnie a problem prześwitywania i pojawiających się dziwnych rzeczy pozostał. Odpowiedź nie na temat

1 użytkowników online, w tym zalogowanych: 0, gości: 1