I have GTK+ (Vala) app that has Main Window with a ScrolledWindow with a HPaned with two VTE Terminals in it. In some cases terminal itselfs resizes the paned. I don't want to allow terminal resize it, I only want to allow user to move with splitter and resize it.
I dont set any properties:
var sw1 = new Gtk.ScrolledWindow(null, null);
var sw2 = new Gtk.ScrolledWindow(null, null);
var paned = new Gtk.HPaned();
paned.pack1(sw1, true, true);
paned.pack2(sw2, true, true);
var main_box = new Gtk.VBox(false, 0);
main_box.pack_start(this.menubar, false);
main_box.pack_start(paned);
this.add(main_box);
How to do that? Why the Terminal (ScrolledWindow) is trying to resize? How can I prevent this behavior? Thanks.
The solution is to set
sw1.set_size_request(-1, 300);
sw2.set_size_request(-1, 300);
so it wont "scretch" while there are less lines.
Related
I am trying to make a Stack and StackSwitcher whose pages associated tabs can be added and deleted dynamically. To delete the associated widget in the stack and the tab in the StackSwitcher, I want to have a small delete button in the tab. I have found an example similar to this in the gtk3-widget-factory, screenshot shown below.
However, this uses a Notebook and I would like to be able to use the Stack/StackSwitcher setup instead of a Notebook (I don't like how the Notebook creates a background to its pages). I can't figure out how to change the widget that is displayed in the StackSwitcher for each page in the Stack. My intuition is that I should just be able to replace the Label in the StackSwitcher with a Box that has been packed with a Label and Button that has a callback that goes and removes the page and the tab. But I am not able to do this with how I am currently creating the pages of the Stack, which is by calling stack.add_titled(). The StackSwitcher that has been assigned to that stack just automatically picks up the labels with no way of editing them that I have found.
Is there a way to do this for a Stack and StackSwitcher? If not, I would also appreciate some advice for doing it with a Notebook as I have not even been able to recreate what I saw in the widget factory (above). This is the code that I have attempting to recreate it:
void main (string[] args) {
Gtk.init (ref args);
var window = new Window ();
window.title = "Example Program";
window.border_width = 10;
window.window_position = WindowPosition.CENTER;
window.set_default_size (350, 70);
window.destroy.connect (Gtk.main_quit);
Notebook note = new Notebook();
Box tabBox = new Box(Orientation.HORIZONTAL, 0);
Label tabLabel = new Label("Closable Tab");
Button closeButton = new Button.from_icon_name("window-close-symbolic", IconSize.BUTTON);
tabBox.pack_start(tabLabel, false, false, 0);
tabBox.pack_start(closeButton, false, false, 0);
Label displayLabel = new Label("this page should be closeable");
note.append_page(displayLabel, tabBox);
window.add(note);
window.show_all();
Gtk.main ();
}
which just creates an empty Notebook tab like this:
and I don't get any error messages about creating that tab failing so I don't know what to do. Any help is appreciated.
I use one JTextArea and JScrollBar. It has this problem when I run it and it will fill by text, I can't navigate it. i.e. when I click on arrowkey on scrolbar, nothing happen. although I write the update code for it (by using API), but it doesn't work well. What shall i do? Thanks in advance.
I show my code as bellow:
JTextArea Result_field = new JTextArea(5,10);
Result_field.setPreferredSize(new Dimension(5, 10));
JScrollPane scrollPane = new JScrollPane( Result_field );
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
DefaultCaret caret = (DefaultCaret)Result_field.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
PrintStream printStream = new PrintStream(new CustomOutputStreamm(Result_field));
System.setOut(printStream);
MainPanel.add(scrollPane,gbc);
I found out my problem, although we define one JTextArea or ... by the size, But after that we should determine the prefer size again.
//created a JScrollPane and when i run it the scrollbars will automatically go to the most bottom of my textarea, but i need it to be on top.
thank you in advance! =)
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(22, 86, 262, 57);
content.add(scrollPane);
//the text area used
JTextArea txtrTryingTryingTrying = new JTextArea();
scrollPane.setViewportView(txtrTryingTryingTrying);
txtrTryingTryingTrying.setText("-------");
I've been trying as well, and found a solution.
There is a useful method called: setCaretPosition(int)
After you use
component.setText("Text here");
You must use
component.setCaretPosition(0); //0 will set it to the top
In your case, you must add setCaretPosition() after setText
JTextArea txtrTryingTryingTrying = new JTextArea();
scrollPane.setViewportView(txtrTryingTryingTrying);
txtrTryingTryingTrying.setText("-------");
txtrTryingTryingTrying.setCaretPosition(0);
I'm new to pyGTK, and now I'm trying to create a menubar with a fixed layout, but I only get a background on the items, not on the entire bar. My code:
import gtk
class App(gtk.Window):
def __init__(self):
super(App,self).__init__()
self.set_size_request(640,480)
self.set_position(gtk.WIN_POS_CENTER)
menubar = gtk.MenuBar()
menu_file= gtk.Menu()
menuitem_file = gtk.MenuItem("File")
menuitem_file.set_submenu(menu_file)
menuitem_exit = gtk.MenuItem("Exit")
menuitem_exit.connect("activate",gtk.main_quit)
menu_file.append(menuitem_exit)
menubar.append(menuitem_file)
fixed = gtk.Fixed()
vbox = gtk.VBox(False, 2)
vbox.pack_start(menubar, False, False, 0)
fixed.add(vbox)
self.add(fixed)
self.connect("destroy",gtk.main_quit)
self.show_all()
App ()
gtk.main ()
You need to make vbox request size, e.g. add vbox.set_size_request (300,50) and see the difference. It is not correct size, but then I don't know why you use gtk.Fixed at all. In 99.95% of case you don't need gtk.Fixed. And especially if you are new to GTK+ you might think you need it while you actually don't.
In my eclipse RCP application there are a few buttons & few input boxes & this below Text component. My problem is as soon as I press one of the buttons a cursor starts blinking in the below test component. Can you please let me know how to solve this.
I tried:
setting focus to false for Text.
SWT.READ_ONLY for Text .
Code:
Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_NO);
protocolFilterDescription.setCursor(cursor);
Nothing seems to get rid of this unnecessary cursor.
protocolFilterDescription = new Text(parent, SWT.NONE | SWT.READ_ONLY );
FormData protocolFilterDescriptionLData = new FormData();
protocolFilterDescriptionLData.left = new FormAttachment(0, 1000, 650);
protocolFilterDescriptionLData.top = new FormAttachment(0, 1000, 290);
protocolFilterDescriptionLData.width = 450;
protocolFilterDescriptionLData.height = 12;
protocolFilterDescription.setLayoutData(protocolFilterDescriptionLData);
protocolFilterDescription.setForeground(new Color(parent.getDisplay(),
204, 153, 0));
protocolFilterDescription.setBackground(Display.getCurrent()
.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
protocolFilterDescription.setFont(new Font(parent.getDisplay(),"Verdana",
6, 1));
protocolFilterDescription
.setText("captured");
You have to set the focus of some other SWT component to true to remove the focus from the Text component.
You'll probably have to do this in an ActionListener.
If you want to completely remove the cursor from the Text control (which implies inability to perform a selection there, etc), try calling setEnabled(false) on it.
Also, such requirement suggests that you maybe don't need Text component at all, and could use Label instead.