Anonymous wrote:Are there plans to add such a functionality in the future?
Yes. In fact, this is now available in the latest v2.1.1 build. For example, here is an example TitlePanel class...
- Code: Select all
package com.swtdesigner.testcases.swing;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.SwingConstants;
public class TitlePanel extends JPanel {
private JTabbedPane m_TabbedPane;
private static final long serialVersionUID = 1307772213100636561L;
private JPanel m_Content;
private JLabel m_Label;
public TitlePanel() {
super();
setBackground(Color.YELLOW);
setLayout(new BorderLayout());
{
m_Label = new JLabel();
m_Label.setOpaque(true);
m_Label.setBackground(Color.ORANGE);
m_Label.setHorizontalAlignment(SwingConstants.CENTER);
add(m_Label, BorderLayout.NORTH);
m_Label.setText("New JLabel");
}
{
m_Content = new JPanel();
m_Content.setLayout(new GridBagLayout());
add(m_Content, BorderLayout.CENTER);
}
}
public String getTitle() {
return m_Label.getText();
}
public void setTitle(String title) {
m_Label.setText(title);
}
public JPanel getContent() {
return m_Content;
}
}
Note that the inner panel is exposed via a public accessor. The text on the embedded label is also exposed by public accessors.
We can then use this in another class...
- Code: Select all
package com.swtdesigner.testcases.swing;
import javax.swing.JFrame;
import com.swtdesigner.testcases.swing.TitlePanel;
import java.awt.BorderLayout;
import javax.swing.JButton;
public class TitlePanelTestCase extends JFrame {
public static void main(String args[]) {
TitlePanelTestCase frame = new TitlePanelTestCase();
frame.setBounds(100, 100, 414, 326);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
public TitlePanelTestCase() {
super();
final TitlePanel titlePanel = new TitlePanel();
titlePanel.getContent().setLayout(null);
final JButton button = new JButton();
button.setBounds(35, 35, 100, 65);
titlePanel.getContent().add(button);
button.setText("New JButton");
final JButton button_1 = new JButton();
button_1.setBounds(270, 190, 110, 70);
titlePanel.getContent().add(button_1);
button_1.setText("New JButton");
titlePanel.setTitle("This is a new title");
getContentPane().add(titlePanel, BorderLayout.CENTER);
}
}
We can add widgets to the inner container and even change the label on the embedded label...