Java Reference
In-Depth Information
JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
this.jFrame.setContentPane(scrollPane);
this.jFrame.pack();
this.jFrame.setSize(300, 400);
this.jFrame.setVisible(true);
}
public void setTitle(String title) {
jFrame.setTitle(title);
}
public void addPanel(String message) {
JPanel pane = new JPanel();
pane.add(new JLabel(message));
mainPane.add(pane);
}
public JFrame getJFrame() {
return jFrame;
}
}
import javax.swing.JFrame;
public abstract class WindowDecorator implements Window {
private final Window window;
public WindowDecorator(Window window) {
this.window = window;
}
public void setTitle(String title) {
window.setTitle(title);
}
public void addPanel(String message) {
window.addPanel(message);
}
public JFrame getJFrame() {
return window.getJFrame();
}
public Window getWindow() {
return window;
}
}
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
public class NaggingWindowDecorator extends WindowDecorator {
public NaggingWindowDecorator(Window window) {
super(window);
// Add a simple message just to show the decorator is working:
getWindow().addPanel("Decorated with NaggingWindowDecorator");
getWindow().getJFrame().setAlwaysOnTop(true);
getWindow().getJFrame().setResizable(false);
// The code below will prevent users from minimizing the window
// by immediately re-opening minimized windows
// In a real life context, you'd of course resort to the full suite
Search WWH ::




Custom Search