-
Bug
-
Resolution: Fixed
-
P3
-
1.1, 1.2.0
-
1.2.2
-
generic, sparc
-
generic, solaris_2.5.1, solaris_2.6
JToolBar.setVisible(false) affects only buttons within the toolbar.. not
the toolbar itself... you have to force a redraw by draggin the frame to
make final effect appear...
run the following code on any text file and use the toggle button to toggle
the toolbar on/off and view the results on the frame... extend/contract
the frame border to view what the results should be... repaint calls to lazily
redraw the frame are useless...
run with: java textpane <filename>
import java.awt.*;
import java.io.*;
import java.beans.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
public class textpane extends JEditorPane implements ActionListener {
boolean ToolBarVisible = true;
JToolBar toolbar;
JScrollPane scroller;
JPanel panel;
JViewport vp;
textpane () {
super();
scroller = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEE
DED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
vp = scroller.getViewport();
vp.add(this);
vp.setBackingStoreEnabled(true);
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add("North", this.EditorToolBar());
panel.add("Center", scroller);
panel.add("South", this.TestToolBar());
}
public JToolBar EditorToolBar() {
toolbar = new JToolBar();
JButton btn1 = new JButton("button");
toolbar.add(btn1);
return toolbar;
}
public JToolBar TestToolBar() {
JToolBar testToolBar = new JToolBar();
JButton visibletool = new JButton("Toggle toolbar on/off");
visibletool.setToolTipText("Toggle ToolBar Visible");
visibletool.setActionCommand("TBV");
visibletool.addActionListener(this);
testToolBar.add(visibletool);
return testToolBar;
}
public void actionPerformed(ActionEvent Evt) {
String cmd = Evt.getActionCommand();
if("TBV".equals(cmd)) {
setToolBarVisible(!getToolBarVisible());
}
}
public void setToolBarVisible(boolean visible) {
ToolBarVisible = visible;
toolbar.setVisible(visible);
repaint();
}
public boolean getToolBarVisible() {
return ToolBarVisible;
}
public void OpenFile(String fileName) {
Thread loader = new fileloader(fileName);
loader.start();
}
class fileloader extends Thread {
String file;
fileloader(String myfile) {
setPriority(3);
file = myfile;
}
public void run() {
File f = new File(file);
try {
Reader in = new FileReader(f);
read(in, f);
}
catch (IOException e) {
System.err.println(e.toString());
}
}
}
public static void main(String[] args) {
try {
UIManager myui = new UIManager();
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassNa
me());
//myui.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
;
} catch (Exception exc) {
System.err.println("Error loading L&F: " + exc);
}
textpane myeditor = new textpane();
JFrame f = new JFrame("SAP: Text Editor");
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add("Center", myeditor.panel);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
f.pack();
f.setSize(600, 400);
f.setVisible(true);
myeditor.setBackground(Color.white);
myeditor.setFont(new Font("Courier", 0, 12));
myeditor.OpenFile(args[0]);
}
}
the toolbar itself... you have to force a redraw by draggin the frame to
make final effect appear...
run the following code on any text file and use the toggle button to toggle
the toolbar on/off and view the results on the frame... extend/contract
the frame border to view what the results should be... repaint calls to lazily
redraw the frame are useless...
run with: java textpane <filename>
import java.awt.*;
import java.io.*;
import java.beans.*;
import java.awt.event.*;
import com.sun.java.swing.*;
import com.sun.java.swing.event.*;
public class textpane extends JEditorPane implements ActionListener {
boolean ToolBarVisible = true;
JToolBar toolbar;
JScrollPane scroller;
JPanel panel;
JViewport vp;
textpane () {
super();
scroller = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEE
DED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
vp = scroller.getViewport();
vp.add(this);
vp.setBackingStoreEnabled(true);
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add("North", this.EditorToolBar());
panel.add("Center", scroller);
panel.add("South", this.TestToolBar());
}
public JToolBar EditorToolBar() {
toolbar = new JToolBar();
JButton btn1 = new JButton("button");
toolbar.add(btn1);
return toolbar;
}
public JToolBar TestToolBar() {
JToolBar testToolBar = new JToolBar();
JButton visibletool = new JButton("Toggle toolbar on/off");
visibletool.setToolTipText("Toggle ToolBar Visible");
visibletool.setActionCommand("TBV");
visibletool.addActionListener(this);
testToolBar.add(visibletool);
return testToolBar;
}
public void actionPerformed(ActionEvent Evt) {
String cmd = Evt.getActionCommand();
if("TBV".equals(cmd)) {
setToolBarVisible(!getToolBarVisible());
}
}
public void setToolBarVisible(boolean visible) {
ToolBarVisible = visible;
toolbar.setVisible(visible);
repaint();
}
public boolean getToolBarVisible() {
return ToolBarVisible;
}
public void OpenFile(String fileName) {
Thread loader = new fileloader(fileName);
loader.start();
}
class fileloader extends Thread {
String file;
fileloader(String myfile) {
setPriority(3);
file = myfile;
}
public void run() {
File f = new File(file);
try {
Reader in = new FileReader(f);
read(in, f);
}
catch (IOException e) {
System.err.println(e.toString());
}
}
}
public static void main(String[] args) {
try {
UIManager myui = new UIManager();
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassNa
me());
//myui.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
;
} catch (Exception exc) {
System.err.println("Error loading L&F: " + exc);
}
textpane myeditor = new textpane();
JFrame f = new JFrame("SAP: Text Editor");
f.getContentPane().setLayout(new BorderLayout());
f.getContentPane().add("Center", myeditor.panel);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
f.pack();
f.setSize(600, 400);
f.setVisible(true);
myeditor.setBackground(Color.white);
myeditor.setFont(new Font("Courier", 0, 12));
myeditor.OpenFile(args[0]);
}
}
- duplicates
-
JDK-4139714 JMenu or JMenuBar should have a method to hide menus
-
- Closed
-