How can I make Window Builder parse an inherited JFrame? [message #1753690] |
Thu, 09 February 2017 00:01 |
Jesse SURNAME Messages: 2 Registered: February 2017 |
Junior Member |
|
|
I have a class BaseWindow with a JFrame mainFrame, and a bunch of methods that work on mainFrame. Actual windows in my app are made by extending BaseWindow.
The class extending BaseWindow inherits mainFrame, and that somehow prevents window builder from "seeing" it when it parses the code. All I see in window builder's design tab is an empty window, but when I run the code everything works fine.
How can I make this approach work with window builder, or "trick" window builder into parsing mainFrame? Here is an example class extending BaseWindow:
package GUIApp;
//took out the imports to save space
class SampleWindowOne extends BaseWindow{
public JLabel txtSampleText;
public JButton btnMagicButton;
public SampleWindowOne() {
initialize();
}
public void run(){
mainFrame.setBounds(getCenteredBounds());
mainFrame.setVisible(true);
}
private void initialize() {
mainFrame = new JFrame();
mainFrame.setBounds(100,100,700,525);
mainFrame.setTitle("Sample Window One");
mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
mainFrame.getContentPane().setLayout(null);
txtSampleText = new JLabel();
txtSampleText.setFont(new Font("Dialog", Font.PLAIN, 25));
txtSampleText.setHorizontalAlignment(SwingConstants.CENTER);
txtSampleText.setText("Sample Window");
txtSampleText.setBounds(12, 50, 674, 51);
mainFrame.getContentPane().add(txtSampleText);
JTextArea txtrLoremIpsumDolor = new JTextArea();
txtrLoremIpsumDolor.setEditable(false);
txtrLoremIpsumDolor.setFont(new Font("Dialog", Font.PLAIN, 16));
txtrLoremIpsumDolor.setForeground(Color.DARK_GRAY);
txtrLoremIpsumDolor.setWrapStyleWord(true);
txtrLoremIpsumDolor.setLineWrap(true);
txtrLoremIpsumDolor.setText("Lorem ipsum dolor sit amet...");
txtrLoremIpsumDolor.setBounds(57, 131, 609, 296);
mainFrame.getContentPane().add(txtrLoremIpsumDolor);
btnMagicButton = new JButton("End Program");
btnMagicButton.setEnabled(false);
btnMagicButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
requestTerminate();
}
});
btnMagicButton.setBounds(257, 451, 175, 25);
mainFrame.getContentPane().add(btnMagicButton);
}
}
Note: My current workaround is to put the line JFrame mainFrame; at the beginning of the class, do what I need to do in window builder, then remove that line again before I run the code.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03570 seconds