Swing Scala Question - 100% expansion of panel
By : Vte. Muedra
Date : March 29 2020, 07:55 AM
may help you . The default layout of JPanel (and Panel) is FlowLayout. Using GridLayout or BorderLayout center should let the JTextArea fill the preferred size. Addendum: Here's a (somewhat) comparable Java Swing example: code :
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
/** @see http://stackoverflow.com/questions/5421319 */
public class TextAreaTest extends JPanel {
private static final int maxWidth = 900;
private static final int maxHeight = 600;
private static final int initXPos = 320;
private static final int initYPos = 260;
private JTextArea ta = new JTextArea();
public TextAreaTest() {
this.setPreferredSize(new Dimension(900, 600));
this.setLayout(new GridLayout());
this.add(ta);
ta.append("Hello, world!");
}
private void display() {
JFrame f = new JFrame("TextAreaTest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocation(initXPos, initYPos);
f.setVisible(true);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new TextAreaTest().display();
}
});
}
}
|
Swing Timer : Don't rely on Swing timers ..Question mark; and concurrency Issues
By : faik berk guler
Date : March 29 2020, 07:55 AM
Hope this helps At the same time i wonder which techniques do Karaoke maker & player software follow? code :
public void moreAccurateTimer(int period) { // Sleep time in
// milliseconds
long beforeTime, timeDiff, sleepTime;
beforeTime = System.currentTimeMillis();
boolean running = true;
while (running) {
doStuff();
timeDiff = System.currentTimeMillis() - beforeTime;
sleepTime = period - timeDiff;
if (sleepTime <= 0L) { // Even if doing stuff took longer than
// period
sleepTime = 5L; // sleep some anyway
}
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
}
beforeTime = System.currentTimeMillis();
}
}
|
Card Layout Panel showing wrong panel - Java Swing
By : user3673323
Date : March 29 2020, 07:55 AM
seems to work fine I don't thin the problem you are experiencing is in the code provided. The one thing I had to change to get this working is add the content pane, which was never added: code :
public MainFrame(){
////////////////////////////resizing
contentPane = new JPanel();
contentPane.setLayout(new CardLayout(20,20));
addPanels();
this.add(this.contentPane); // I added this
////////////////////////listener for closing
}
|
How to resize correctly a panel automatically when another panel is dinamically moving java swing
By : user3537628
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , After using the recommendation of @JBNizet, i have used the BorderLayout https://docs.oracle.com/javase/8/docs/api/java/awt/BorderLayout.html to fit according to my specifications. And working fine now, The button is placed in north direction, the jPanel2 in west direction and jPanel1 in the center.
|
Erase Swing Content Pane/Panel & display a new panel
By : lllf
Date : March 29 2020, 07:55 AM
hop of those help? I have created an applet where when you press the button "Forgot Pass" I erase the current JPanel on the applet & create a new JPanel that displays the JComponents related to Retrieving/Forgetting a password. , Use mainPanel.revalidate(); and/or mainPanel.repaint(); methods.
|