0

Here is a very simple JTable on a JFrame example that I extracted from another web site.

import javax.swing.*;    
public class JTableSimpleSample {    
    JFrame f;    
    JTableSimpleSample(){    
    f=new JFrame();    
    String data[][]={ {"101","Amit","670000"},    
                          {"102","Jai","780000"},    
                          {"101","Sachin","700000"}};    
    String column[]={"ID","NAME","SALARY"};         
    JTable jt=new JTable(data,column);    
    jt.setBounds(30,40,200,300);          
    JScrollPane sp=new JScrollPane(jt);    
    f.add(sp);          
    f.setSize(300,400);    
    f.setVisible(true);    
}     
public static void main(String[] args) {    
    new JTableSimpleSample();    
}    
} 

When resizing this window, the behavior is slightly different depending upon which edge is being used for resizing.

Top - resize the frame by clicking the top edge and it looks pretty clean except it does appear the bottom edge of the JFrame is continually getting repainted making it look like multiple lines exist.

Bottom - resize the frame by clicking the bottom edge looks pretty good as making it large shows a black area until the frame gets to repaint. Depending on how fast you resize the frame determines how much of the black area is visible.

Right - resize the frame by clicking the right edge is very similar to when the bottom edge is used when resizing.

Left - resize the frame by clicking the left edge looks terrible. It is no only similar to when it is resized using the top by showing multiple lines on the right edge, but at times the data itself looks a mess.

Using any of the corners results in a combination of 2 from any of the above scenarios.

Question/Objective : 1 - Why such different behavior?

2 - Is it possible to have it so that only an outline of the frame is shown when resizing and instead of a black background when resizing, have it transparent. Something like the following if the bottom right corner is used for resizing. The red lines are used to make it obvious as to the objective but it can very well remain black :

Outline Example

I did review Black outline while resizing JFrame but didn't fully understand the usage of the timer. Was not sure if there exists a property or if this would be managed via a mouse handler tied to the JFrame.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Unhandled Exception
  • 1,427
  • 14
  • 30
  • I think what you're seeing is an effect for how Java does it's windowing with regards to coordinates. When you alter the top or left you're changing the anchor point forcing a complete redraw. When you alter the right or bottom, you're only changing the width/height so anchor side appear to not move. This problem *MIGHT* go away if you were using SWT since that uses native code. – Ryan Mar 09 '20 at 13:13
  • I am not able to reproduce your issue. Which version of Java are you using? On which OS are you running? – VGR Mar 09 '20 at 15:39
  • Running JDK 1.8.0_181-b13 on Windows 10. Keep in mind, when I am resizing the window, I am doing it a bit rapidly. Granted it is probably excessive but it does show the issue much better than slowly resizing. – Unhandled Exception Mar 09 '20 at 16:11

0 Answers0