Win a copy of Microservices Testing (Live Project) this week in the Spring forum!

Martin webster

Greenhorn
+ Follow
since Jun 20, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Martin webster

Hi,
One approach is to place a JLabel within the content of the panel and then set the icon on the label...
Another approach, which I prefer, is to override the paintComponent method...This is best used for creating a background image for your panels...
public class ImagePnl extends JPanel
{
ImageIcon ic = new ImageIcon("montage.jpg");
public ImagePnl()
{
}
public void paintComponent(Graphics g)
{
g.drawImage(ic.getImage() ,0,0,Color.red, null);
}
}
I use imageIcon waits until the image is loaded, which would occur during construction...
20 years ago
Hi,
I would probably just use a series of buttons... they will give you the required behaviour, and with the ability to attach a button group you can guarentee that only one is selected....
Another approach is to use a List with a custom listRenderer. The renderer can display an image, and a border can be easily attached...
20 years ago
Does anyone know the difference between a Pane and a Panel. I have noticed that throughout swing, there are many types of pane.... eg JScrollPane, JTabbedPane, JOptionPane etc. Does anyone know why they are called Pane and not Panel?
If Pane represents some sort of behaviour then shouldn't there be a Pane interface ?
The reason I want to know this, is that I am creating some components that extend JPanel, and don't know whether to use a Pane or a Panel suffix.
20 years ago
Freaky.... Looks like england on a summers day
I think your answer is in the question
JButton but = new JButton();
but.setMargin(new Insets(top, left, bottom, right));
// where top, left, bottom and right are ints...
21 years ago
Thanks Jane,
It has all become clear. The writeUTF method is fixed to use the UTF-8 encoding mechanism to convert a character to a byte. However, the Writer mechanism (eg file writer) gives the programmer the ability to specify the encoding strategy to use.
Superb! Nice day for a walk.
Hi
I've always read that readers and writers are specialised in performing input and output of Unicode characters, such that they perform the required conversion to UTF format.
However, what I don't understand is why there exists a writeUTF(String s) in the DataOutputStream, which should be more concerned with bytes ....
Thanks....
I guess I'll wait until we move to 1.4...
21 years ago
Hi,
This a class that I've created that manages Internal Frames for a windows menu. It is giving a windows menu on construction, and then every time you create an internal frame you would just call
frameCreated(JInternalFrame jrm). This class also contains the ability to change the menu item when the frame Icon or title changes.
<PRE>
/**
* Manages the active window menu. A menu that is to be used to contain the active
* windows is passed in as part of the constructor to this class. When a frame is
* launched then the frameCreated method must be called to add a menu item to the
* menu. When this frame is closed then it automatically calls the frameClosed method
* which will remove the menu item

*
* Currently these are just standard mnu items.
*/
public class InternalFrameMenuManager
{
HashMap _map = new HashMap();
JMenu _windowMenu;
private int _windowCount = 0;
private JSeparator _seperator = new JSeparator();
/**
* Constructor accepting a menu
* @param windowMenu the menu to be used to attach the active window menu items
*/
public InternalFrameMenuManager(JMenu windowMenu)
{
_windowMenu = windowMenu;
}
/**
* called automatically when the frame is closed. This removes the menu item
* from the menu
* @param frm The closing internal frame
*/
public void frameClosed(JInternalFrame frm)
{
_windowCount--;
JMenuItem item = (JMenuItem)_map.get(frm);
_windowMenu.remove(item);
if (_windowCount==0)
{
_windowMenu.remove(_seperator);
}
}
/**
* Called when the frame is created. This adds a menu item to the menu
* param frm The internal frame
*/
public void frameCreated(final JInternalFrame frm)
{
_windowCount++;
if (_windowCount==1)
{
_windowMenu.add(_seperator);
}
frm.addInternalFrameListener(new InternalFrameAdapter()
{
public void internalFrameClosed(InternalFrameEvent e)
{
frameClosed(frm);
}
});
frm.addPropertyChangeListener (new PropertyChangeListener()
{
public void propertyChange(PropertyChangeEvent pce)
{
if (pce.getPropertyName().equals("title"))
{
JMenuItem item = (JMenuItem)_map.get(frm);
item.setText(frm.getTitle());
}
else if (pce.getPropertyName().equalsIgnoreCase("frameIcon"))
{
JMenuItem item = (JMenuItem)_map.get(frm);
item.setIcon(frm.getFrameIcon());
}
}
});
JMenuItem item = new JMenuItem(frm.getTitle(), frm.getFrameIcon());
item.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
try
{
frm.setSelected(true);
if (frm.isIcon())
{
frm.setIcon(false);
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
});
_map.put(frm, item);
_windowMenu.add(item);
}
}
</PRE>
21 years ago
Hello
Does anyone know if it is possible to programmatically maximise JFrame ?
There appears to be a setState(int state) accepting Frame.Normal and Frame.Iconified... but no maximised.
21 years ago
Hi,
If you want to display a gif, then the easiest approach to take is to create an ImageIcon, whose constructor takes the name of the image....
i.e
dlg.setImageIcon(new ImageIcon("image1.gif"));
21 years ago
I think this question is all down to the wording used.
To be pedantic.. I would just say (a) is the correct answer as a method comforming to (c) could still be invalid. i.e
public void run(boolean b)
Thanks Desai,
I've reduced the dependencies between the packages. I'm still a little unsure whether a package should be dependent on a sub-package, or the other way round....I guess it doesn't make much difference aslong as the dependency is modeled..
Hello,
I'm a little confused on when to use sub packages, and the dependencies that should exist between a package and a sub package.
In Swing and AWT there seems to be quite a few cyclic dependencies between packages and sub packages.
For Example,
JTable exists in the javax.swing package. This class referencies classes( eg DefaultTableCellRenderer) within javax.swing.table.
However the DefaultTableCellRenderer class in packagage javax.swing.table referencies javax.swing.JTable. Hence circular dependency!!
The question is, should packages be dependent on subpackages ? or vice-versa ?... or should we be trying to avoid circular dependencies at all?... or am I getting worried about something that I shouldn't be worried about at all, and probably get out more!
Hi,
Are you sure that the short circuit | | operator will always avaluate both operands. Surely if the left hand operator is true then it won't need to evalaute the right had side ?