Sunday, 13 August 2017

image - Java wrong view JPanel

I have a desktop application in swing. I have a JPanel in which the image as the background and in it two buttons and a JScrollPane as shown in the picture Frame with JPanel. I have a function (showLabel()) which, when JScrollPane the end, add JLabel with transparent images and disappear a few seconds. The problem is that when you add JLabel. JLabel bad shows as seen in Fig Bad shows. Can you help me with my problem?



 public class MainWindow {

private JFrame frame;
private PanelPopis panelPopis = new PanelPopis(this);
private MyPaint myPaint;


public MainWindow {

setWindow():
BufferedImage image1 = ImageIO.read(getClass().getClassLoader().getResource("poz.png"));

this.myPaint = new MyPaint(image1);
this.frame.add(myPaint);

this.myPaint.add(panelPopis.setPanel());


}


private void setWindow() {
this.frame = new JFrame("DD");
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.frame.setSize(400, 680);
this.frame.setResizable(false);
this.frame.setLocationRelativeTo(null);
}


private void showLabel(){

JLabel label = new JLabel();

label.setIcon(new ImageIcon(new ImageIcon(getClass().getClassLoader().getResource("postEn.png")).getImage().getScaledInstance(395, 653, Image.SCALE_DEFAULT)));
label.setBackground(new Color(0, 0, 0, 10));
label.setOpaque(true);

this.frame.invalidate();

this.frame.add(label);
this.frame.revalidate();

int delay2 = 3000; // milliseconds
ActionListener taskPerformer2 = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
frame.remove(label);
frame.revalidate();
frame.repaint();
}


};
Timer myTimer2 = new Timer(delay2, taskPerformer2);
myTimer2.setRepeats(false);
myTimer2.start();

}


}




public class MyPaint extends JPanel {

private static final long serialVersionUID = 1L;
BufferedImage image;

public MyPaint(BufferedImage image) {
setOpaque(false);
}



public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, 395, 653, this);

}


}




public class PanelPopis extends JPanel {

private static final long serialVersionUID = 7676683627217636485L;

private JButton setLanguage;
private JButton cont;
private JScrollPane scrolPanel;
private JTextArea popis;
private MainWindow mainWindow;


public PanelPopis(MainWindow mainWindow) {
this.mainWindow = mainWindow;

}

public JPanel setPanel() {

JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setOpaque(false);


JPanel panel2 = new JPanel();
Border border = panel2.getBorder();
Border margin = new EmptyBorder(0, 0, 4, 0);
panel2.setBorder(new CompoundBorder(border, margin));

panel2.setOpaque(false);
panel2.add(this.scrolPanel = new JScrollPane(popis));

panel.add(this.setLanguage = new JButton("language settings"), BorderLayout.NORTH);

panel.add(this.cont = new JButton("CONTINUE"), BorderLayout.SOUTH);
panel.add(panel2, BorderLayout.CENTER);

return panel;

}


}

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...